roughike/BottomBar — 8.4k★ trên GitHub (Java). (Deprecated) A custom view component that mimics the new Material Design Bottom Navigation pattern.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
I don't have time to maintain this anymore. I basically wrote the whole library in a rush, without tests, while being a serious expert beginner at the time. As a result, there's a lot of unpredictable moving parts and the tests probably aren't that great either. Don't really know, since I haven't touched this in ages.
I'd recommend you to use the official BottomNavigationView from Google and urge them to implement the features you need. Or use another 3rd party library.
Version 2.0 released!
The latest version before that can be found in the v1 branch
Cleaner code and better APIs
No more unnecessary stuff or spaghetti mess
Now the look, feel and behavior is defined in XML, as it should be
No more nasty regressions, thanks to the automated tests
Everything is a little different compared to earlier, but it's for the greater good!
How to contribute
Changelog
What?
A custom view component that mimics the new Material Design Bottom Navigation pattern.
Does it work on my Grandpa Gary's HTC Dream?
Nope. The minSDK version is API level 11 (Honeycomb).
The icons must be fully opaque, solid black color, 24dp and with no padding. For example, with Android Asset Studio Generic Icon generator, select "TRIM" and make sure the padding is 0dp. Here's what your icons should look like:
Then, add the BottomBar to your layout and give it a resource id for your tabs xml file.
layout/activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- This could be your fragment container, or something -->
<FrameLayout
android:id="@+id/contentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottomBar" />
<com.roughike.bottombar.BottomBar
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
app:bb_tabXmlResource="@xml/bottombar_tabs" />
</RelativeLayout>
Setting up listeners
By default, the tabs don't do anything unless you listen for selection events and do something when the tabs are selected.
MainActivity.java:
public class MainActivity extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BottomBar bottomBar = (BottomBar) findViewById(R.id.bottomBar);
bottomBar.setOnTabSelectListener(new OnTabSelectListener() {
@Override
public void onTabSelected(@IdRes int tabId) {
if (tabId == R.id.tab_favorites) {
// The tab with id R.id.tab_favorites was selected,
// change your content accordingly.
}
}
});
}
}
If you want to listen for reselection events, here's how you do it:
bottomBar.setOnTabReselectListener(new OnTabReselectListener() {
@Override
public void onTabReSelected(@IdRes int tabId) {
if (tabId == R.id.tab_favorites) {
// The tab with id R.id.tab_favorites was reselected,
// change your content accordingly.
}
}
});
Intercepting tab selections
If you want to conditionally cancel selection of any tab, you absolutely can. Just assign a TabSelectionInterceptor to the BottomBar, and return true from the shouldInterceptTabSelection() method.
bottomBar.setTabSelectionInterceptor(new TabSelectionInterceptor() {
@Override
public boolean shouldInterceptTabSelection(@IdRes int oldTabId, @IdRes int newTabId) {
if (newTabId == R.id.tab_pro_feature && !userHasProVersion()) {
startProVersionPurchaseFlow();
return true;
}
return false;
}
});
Changing icons based on selection state
If you want to have different icon when a specific tab is selected, just use state list drawables.
Specify a different layout for your activity in res/layout-sw600dp folder and set bb_tabletMode to true.
res/layout-sw600dp/activity_main.xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.roughike.bottombar.BottomBar
android:id="@+id/bottomBar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
app:bb_tabXmlResource="@xml/bottombar_tabs_three"
app:bb_tabletMode="true" />
<!-- This could be your fragment container, or something -->
<FrameLayout
android:id="@+id/contentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="@+id/bottomBar" />
</RelativeLayout>
You can easily add badges for showing an unread message count or new items / whatever you like.
BottomBarTab nearby = bottomBar.getTabWithId(R.id.tab_nearby);
nearby.setBadgeCount(5);
// Remove the badge when you're done with it.
nearby.removeBadge/();
the XML Resource id for your tabs, that reside in values/xml/
bb_tabletMode
if you want the BottomBar to behave differently for tablets. There's an example of this in the sample project!
bb_behavior
shifting: the selected tab is wider than the rest. shy: put the BottomBar inside a CoordinatorLayout and it'll automatically hide on scroll! underNavbar: draw the BottomBar under the navBar!
bb_inActiveTabAlpha
the alpha value for inactive tabs, that's used in the tab icons and titles.
bb_activeTabAlpha
the alpha value for active tabs, that's used in the tab icons and titles.
bb_inActiveTabColor
the color for inactive tabs, that's used in the tab icons and titles.
bb_activeTabColor
the color for active tabs, that's used in the tab icons and titles.
bb_badgeBackgroundColor
the background color for any Badges in this BottomBar.
bb_badgesHideWhenActive
whether badges should be hidden for active tabs, defaults to true.
bb_titleTextAppearance
custom textAppearance for the titles
bb_titleTypeFace
path for your custom font file, such as fonts/MySuperDuperFont.ttf. In that case your font path would look like src/main/assets/fonts/MySuperDuperFont.ttf, but you only need to provide fonts/MySuperDuperFont.ttf, as the asset folder will be auto-filled for you.
bb_showShadow
controls whether the shadow is shown or hidden, defaults to true.
the color for inactive tabs, that's used in the tab icons and titles.
activeColor
the color for active tabs, that's used in the tab icons and titles.
barColorWhenSelected
the color that the whole BottomBar should be when selected this tab.
badgeBackgroundColor
the background color for any Badges in this tab.
badgeHidesWhenActive
whether or not the badge should be hidden when this tab is selected, defaults to true.
Apps using BottomBar
Nearby : A location-based social networking app with over 5 million users.
FragNav : An Android Library for managing multiple stacks of Fragments. BottomBar is used in the sample app.
BottomNavigationBar : BottomBar ported to C# for Xamarin developers
KyudoScoreBookTeam : BottomBar is used in the KyudoScoreBookTeam app.
memeham : BottomBar is used in the memeham app.
NewsCatchr : A newsreader app, which uses this BottomBar library.
GitSkarios : A Github android App, to visit your repositories, gists and more!
Code
Send me a pull request with modified README.md to get a shoutout!
Contributions
Feel free to create issues and pull requests.
When creating pull requests, more is more: I'd like to see ten small pull requests separated by feature rather than all those combined into a huge one.
License
BottomBar library for Android
Copyright (c) 2016 Iiro Krankka (http://github.com/roughike).
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
roughike/BottomBar thuộc nhóm Mobile trên TopGit, cùng 5 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về roughike/BottomBar ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/roughike/BottomBar là nguồn chính thức.
roughike/BottomBar có bao nhiêu sao?
roughike/BottomBar có 8.4k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/roughike/BottomBar. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
roughike/BottomBar có phải mã nguồn mở không?
Có — roughike/BottomBar phát hành theo license Apache-2.0, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/roughike/BottomBar.
roughike/BottomBar còn đang phát triển không?
Commit gần nhất trên roughike/BottomBar là 4.9 năm trước (theo timestamp GitHub). Repo có 1.5k fork — một chỉ báo về mức độ quan tâm của cộng đồng.
roughike/BottomBar dùng license gì?
roughike/BottomBar phát hành theo license Apache-2.0. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
roughike/BottomBar là gì?
roughike/BottomBar (roughike/BottomBar) là dự án Java trên GitHub. Theo mô tả gốc: (Deprecated) A custom view component that mimics the new Material Design Bottom Navigation pattern.
roughike/BottomBar viết bằng ngôn ngữ gì?
roughike/BottomBar chủ yếu viết bằng Java. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc BottomBar có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về BottomBar.