← Back to roughike/BottomBar

How to Deploy & Use roughike/BottomBar

BottomBar Deployment & Usage Guide

Deprecation Notice: This library is deprecated. The maintainer recommends using the official BottomNavigationView from Google's Material Components instead.

Prerequisites

  • Android Studio 2.0 or higher
  • Android SDK API Level 11+ (Android 3.0 Honeycomb minimum)
  • Java 7 or higher
  • Gradle 2.0+ (for compile directive) or 3.0+ (for implementation directive)
  • Build Tools 23.0.2 or higher

Installation

Add the dependency to your app-level build.gradle:

dependencies {
    // For older Gradle versions (pre-3.0)
    compile 'com.roughike:bottom-bar:2.3.1'
    
    // For Gradle 3.0+ (recommended)
    implementation 'com.roughike:bottom-bar:2.3.1'
}

Maven (alternative):

<dependency>
  <groupId>com.roughike</groupId>
  <artifactId>bottom-bar</artifactId>
  <version>2.3.1</version>
  <type>pom</type>
</dependency>

Sync your project with Gradle files.

Configuration

1. Prepare Icons

Icons must meet strict specifications:

  • Size: 24dp
  • Color: Solid black (#000000)
  • Opacity: Fully opaque
  • Padding: 0dp (no padding)

Use Android Asset Studio with "TRIM" selected and padding set to 0dp.

2. Define Tabs XML

Create res/xml/bottombar_tabs.xml:

<tabs>
    <tab
        id="@+id/tab_favorites"
        icon="@drawable/ic_favorites"
        title="Favorites" />
    <tab
        id="@+id/tab_nearby"
        icon="@drawable/ic_nearby"
        title="Nearby" />
    <tab
        id="@+id/tab_friends"
        icon="@drawable/ic_friends"
        title="Friends" />
</tabs>

3. Add to Layout

layout/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">

    <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>

4. Implement Listeners

MainActivity.java:

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        BottomBar bottomBar = findViewById(R.id.bottomBar);
        
        // Handle tab selection
        bottomBar.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelected(@IdRes int tabId) {
                if (tabId == R.id.tab_favorites) {
                    // Switch to favorites fragment/content
                }
            }
        });
        
        // Handle tab reselection (clicking already selected tab)
        bottomBar.setOnTabReselectListener(new OnTabReselectListener() {
            @Override
            public void onTabReSelected(@IdRes int tabId) {
                // Handle scroll-to-top or refresh actions
            }
        });
    }
}

5. Optional: Intercept Selections

To conditionally prevent tab selection (e.g., for premium features):

bottomBar.setTabSelectionInterceptor(new TabSelectionInterceptor() {
    @Override
    public boolean shouldInterceptTabSelection(@IdRes int oldTabId, @IdRes int newTabId) {
        if (newTabId == R.id.tab_pro_feature && !userHasProVersion) {
            Toast.makeText(context, "Upgrade to Pro", Toast.LENGTH_SHORT).show();
            return true; // Intercept/cancel selection
        }
        return false; // Allow selection
    }
});

Build & Run

Debug Build

./gradlew assembleDebug

Install on Device

./gradlew installDebug

Running Tests

./gradlew connectedAndroidTest

Deployment

Deploying Apps Using This Library

  1. Generate Signed APK:

    ./gradlew assembleRelease
    
  2. Generate App Bundle (for Google Play):

    ./gradlew bundleRelease
    
  3. ProGuard/R8 Rules (if minification enabled):

    -keep class com.roughike.bottombar.** { *; }
    -keepattributes *Annotation*
    

Publishing the Library (Not Recommended)

While the library is deprecated, if you need to fork and publish internally:

  1. Update gradle.properties with Bintray/Maven credentials
  2. Run ./gradlew bintrayUpload (requires com.novoda:bintray-release plugin)
  3. Or publish to local Maven: ./gradlew publishToMavenLocal

Troubleshooting

IssueSolution
Icons appear wrong size/colorEnsure icons are exactly 24dp, solid black (#000000), with 0dp padding. Use Vector Drawable tinting if needed.
Tabs don't respond to clicksVerify you've set OnTabSelectListener. Without a listener, tabs are non-functional by design.
Min SDK errorsEnsure your build.gradle has minSdkVersion 11 or higher.
CoordinatorLayout issuesThe library includes BottomNavigationBehavior for CoordinatorLayout integration. Ensure you're using android.support.design:coordinatorlayout if using scroll-to-hide features.
Badge not showingUse bottomBar.getTabWithId(R.id.tab_id).setBadgeCount(5) and ensure badge colors are set via XML attributes or programmatically.
Gradle sync failsReplace compile with implementation if using Android Gradle Plugin 3.0+.
Resources not foundVerify bb_tabXmlResource points to a valid XML resource in res/xml/.

Migration Path

Since this library is deprecated, plan migration to:

implementation 'com.google.android.material:material:1.9.0'

Then replace BottomBar with BottomNavigationView in your layouts and update navigation logic to use setOnItemSelectedListener().