# BottomBar (Deprecated) 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. [![Build Status](https://travis-ci.org/roughike/BottomBar.svg?branch=master)](https://travis-ci.org/roughike/BottomBar) [![Coverage Status](https://coveralls.io/repos/github/roughike/BottomBar/badge.svg?branch=development)](https://coveralls.io/github/roughike/BottomBar?branch=master) [![Download](https://api.bintray.com/packages/roughike/maven/bottom-bar/images/download.svg)](https://bintray.com/roughike/maven/bottom-bar/_latestVersion) ## Version 2.0 released! [The latest version before that can be found in the v1 branch](https://github.com/roughike/BottomBar/tree/v1) * 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](https://github.com/roughike/BottomBar/blob/master/README.md#contributions) [Changelog](https://github.com/roughike/BottomBar/blob/master/CHANGELOG.md) ## What? A custom view component that mimics the new [Material Design Bottom Navigation pattern](https://www.google.com/design/spec/components/bottom-navigation.html). ## Does it work on my Grandpa Gary's HTC Dream? Nope. The minSDK version is **API level 11 (Honeycomb).** ## Gimme that Gradle sweetness, pls? ```groovy compile 'com.roughike:bottom-bar:2.3.1' ``` **Maven:** ```xml com.roughike bottom-bar 2.3.1 pom ``` ## How? You can add items by **writing a XML resource file**. ### Creating the icons The icons must be fully opaque, solid black color, 24dp and **with no padding**. For example, [with Android Asset Studio Generic Icon generator](https://romannurik.github.io/AndroidAssetStudio/icons-generic.html), select "TRIM" and make sure the padding is 0dp. Here's what your icons should look like: ![Sample icons](https://raw.githubusercontent.com/roughike/BottomBar/master/graphics/icons-howto.png) ### Adding items from XML resource Define your tabs in an XML resource file. **res/xml/bottombar_tabs.xml:** ```xml ``` Then, add the BottomBar to your layout and give it a resource id for your tabs xml file. **layout/activity_main.xml** ```xml ``` ### 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:** ```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: ```java 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. ```java 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. **res/drawable/my_tab_icon.xml** ```xml ``` **res/xml/bottombar_tabs.xml** ```xml ... ... ``` ### Those color changing tabs look dope. Howdoidodat? Just add ```barColorWhenSelected``` to each tab. When that tab is selected, the whole BottomBar background color is changed with a nice animation. **res/xml/bottombar_tabs.xml** ```xml ``` ### How do I draw it under the navbar? First, define a style that is a child of your main application theme: **res/values-v21/styles.xml** ```xml ``` You'll also have to **make a stub version of the same theme** to avoid crashes in previous API levels than Lollipop: **res/values/styles.xml** ```xml