Convert Figma logo to code with AI

ittianyu logoBottomNavigationViewEx

An android lib for enhancing BottomNavigationView. 一个增强BottomNavigationView的安卓库。

3,450
557
3,450
58

Top Related Projects

(Deprecated) A custom view component that mimics the new Material Design Bottom Navigation pattern.

A library to reproduce the behavior of the Bottom Navigation guidelines from Material Design.

This Library helps users to use Bottom Navigation Bar (A new pattern from google) with ease and allows ton of customizations

An bottom navigation bar for Android

Bottom Navigation widget component inspired by the Google Material Design Guidelines at https://www.google.com/design/spec/components/bottom-navigation.html

Yet another material bottom bar library for Android

Quick Overview

BottomNavigationViewEx is an enhanced version of Android's BottomNavigationView. It extends the functionality of the original component, offering additional features and customization options for creating more flexible and visually appealing bottom navigation bars in Android applications.

Pros

  • Provides more customization options than the standard BottomNavigationView
  • Supports dynamic item addition and removal
  • Allows for disabling the shift mode for a consistent appearance
  • Offers easy integration with ViewPager for smooth navigation

Cons

  • May require additional maintenance as Android's native BottomNavigationView evolves
  • Potential performance overhead due to added features
  • Limited documentation and examples for some advanced use cases
  • Dependency on a third-party library instead of using native Android components

Code Examples

  1. Disabling shift mode and setting custom colors:
val bottomNavEx = findViewById<BottomNavigationViewEx>(R.id.bottomNavEx)
bottomNavEx.enableShiftingMode(false)
bottomNavEx.enableItemShiftingMode(false)
bottomNavEx.setTextVisibility(false)
bottomNavEx.setItemBackground(R.drawable.custom_background)
bottomNavEx.setIconTintList(ContextCompat.getColorStateList(this, R.color.custom_tint))
  1. Adding and removing items dynamically:
val bottomNavEx = findViewById<BottomNavigationViewEx>(R.id.bottomNavEx)
val newItem = BottomNavigationItemView(this)
newItem.setIcon(R.drawable.new_icon)
newItem.setTitle("New Item")
bottomNavEx.menu.add(Menu.NONE, R.id.new_item_id, Menu.NONE, "New Item")
bottomNavEx.addView(newItem)

// Removing an item
bottomNavEx.menu.removeItem(R.id.item_to_remove)
  1. Setting up with ViewPager:
val bottomNavEx = findViewById<BottomNavigationViewEx>(R.id.bottomNavEx)
val viewPager = findViewById<ViewPager>(R.id.viewPager)

bottomNavEx.setupWithViewPager(viewPager)

Getting Started

To use BottomNavigationViewEx in your Android project:

  1. Add the dependency to your app's build.gradle file:
dependencies {
    implementation 'com.github.ittianyu:BottomNavigationViewEx:2.0.4'
}
  1. Add the BottomNavigationViewEx to your layout XML:
<com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx
    android:id="@+id/bottomNavEx"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:menu="@menu/bottom_nav_menu" />
  1. Initialize and customize in your Activity or Fragment:
val bottomNavEx = findViewById<BottomNavigationViewEx>(R.id.bottomNavEx)
bottomNavEx.enableAnimation(false)
bottomNavEx.setTextSize(12f)

Competitor Comparisons

(Deprecated) A custom view component that mimics the new Material Design Bottom Navigation pattern.

Pros of BottomBar

  • More customizable appearance with extensive theming options
  • Supports badges and notifications out of the box
  • Easier to implement shifting behavior and animations

Cons of BottomBar

  • Not based on the official Material Design component
  • May require more setup and configuration
  • Less frequently updated compared to BottomNavigationViewEx

Code Comparison

BottomBar implementation:

val bottomBar = findViewById<BottomBar>(R.id.bottomBar)
bottomBar.setOnTabSelectListener { tabId ->
    // Handle tab selection
}

BottomNavigationViewEx implementation:

val bottomNav = findViewById<BottomNavigationViewEx>(R.id.bottom_nav)
bottomNav.setOnNavigationItemSelectedListener { item ->
    // Handle item selection
    true
}

Both libraries offer similar functionality, but BottomNavigationViewEx is based on the official Android BottomNavigationView, making it more aligned with Material Design guidelines. BottomBar provides more customization options out of the box, which can be beneficial for projects requiring unique designs. However, BottomNavigationViewEx is more frequently updated and maintained, ensuring better compatibility with the latest Android versions and support libraries.

A library to reproduce the behavior of the Bottom Navigation guidelines from Material Design.

Pros of ahbottomnavigation

  • More customizable with features like colored navigation and badge support
  • Smoother animations and transitions between items
  • Better support for landscape mode and tablets

Cons of ahbottomnavigation

  • Requires more setup and configuration compared to BottomNavigationViewEx
  • May have a steeper learning curve for developers new to custom navigation components

Code Comparison

ahbottomnavigation:

val bottomNavigation = findViewById<AHBottomNavigation>(R.id.bottom_navigation)
bottomNavigation.addItem(AHBottomNavigationItem("Item 1", R.drawable.ic_item1))
bottomNavigation.addItem(AHBottomNavigationItem("Item 2", R.drawable.ic_item2))
bottomNavigation.setOnTabSelectedListener { position, wasSelected -> 
    // Handle selection
}

BottomNavigationViewEx:

val bottomNavigation = findViewById<BottomNavigationViewEx>(R.id.bottom_navigation)
bottomNavigation.enableAnimation(false)
bottomNavigation.enableShiftingMode(false)
bottomNavigation.enableItemShiftingMode(false)
bottomNavigation.setOnNavigationItemSelectedListener { item ->
    // Handle selection
    true
}

Both libraries offer enhanced functionality for bottom navigation in Android apps. ahbottomnavigation provides more advanced customization options and smoother animations, while BottomNavigationViewEx offers a simpler setup with fewer configuration steps. The choice between the two depends on the specific requirements of your project and the level of customization needed.

This Library helps users to use Bottom Navigation Bar (A new pattern from google) with ease and allows ton of customizations

Pros of BottomNavigation

  • More customizable with additional features like shifting mode and text scaleType
  • Supports badges on menu items
  • Better documentation and examples provided

Cons of BottomNavigation

  • Less actively maintained (last update in 2019)
  • May not fully support the latest Material Design guidelines
  • Slightly more complex implementation compared to BottomNavigationViewEx

Code Comparison

BottomNavigation:

BottomNavigationBar bottomNavigationBar = (BottomNavigationBar) findViewById(R.id.bottom_navigation_bar);
bottomNavigationBar
    .addItem(new BottomNavigationItem(R.drawable.ic_home, "Home"))
    .addItem(new BottomNavigationItem(R.drawable.ic_search, "Search"))
    .initialise();

BottomNavigationViewEx:

BottomNavigationViewEx bnve = (BottomNavigationViewEx) findViewById(R.id.bnve);
bnve.enableAnimation(false);
bnve.enableShiftingMode(false);
bnve.enableItemShiftingMode(false);

Both libraries offer similar functionality for implementing bottom navigation in Android apps. BottomNavigation provides more customization options and better documentation, while BottomNavigationViewEx is more actively maintained and aligns closer with the native BottomNavigationView. The choice between the two depends on specific project requirements and preferences for customization vs. simplicity.

An bottom navigation bar for Android

Pros of PagerBottomTabStrip

  • More customizable appearance with various built-in styles and animations
  • Supports vertical layout for tabs
  • Easier integration with ViewPager for smooth page transitions

Cons of PagerBottomTabStrip

  • Less actively maintained (last update was in 2019)
  • Smaller community and fewer resources compared to BottomNavigationViewEx
  • May require more setup and configuration for basic use cases

Code Comparison

PagerBottomTabStrip:

BottomTabLayout bottomTabLayout = findViewById(R.id.bottomTabLayout);
bottomTabLayout.setTabItems(
    new TabItem(this, R.drawable.ic_home, R.drawable.ic_home_selected, "Home"),
    new TabItem(this, R.drawable.ic_search, R.drawable.ic_search_selected, "Search"),
    new TabItem(this, R.drawable.ic_notifications, R.drawable.ic_notifications_selected, "Notifications")
);

BottomNavigationViewEx:

BottomNavigationViewEx bottomNavigationViewEx = findViewById(R.id.bottomNavigation);
bottomNavigationViewEx.enableAnimation(false);
bottomNavigationViewEx.enableShiftingMode(false);
bottomNavigationViewEx.enableItemShiftingMode(false);

Both libraries offer easy-to-use APIs for creating bottom navigation bars in Android applications. PagerBottomTabStrip provides more customization options out of the box, while BottomNavigationViewEx focuses on enhancing the standard BottomNavigationView with additional features. The choice between the two depends on specific project requirements and desired level of customization.

Bottom Navigation widget component inspired by the Google Material Design Guidelines at https://www.google.com/design/spec/components/bottom-navigation.html

Pros of Material-BottomNavigation

  • More comprehensive implementation of Material Design guidelines
  • Supports both fixed and shifting modes out of the box
  • Includes additional customization options for badge styling

Cons of Material-BottomNavigation

  • Less actively maintained (last update was over 3 years ago)
  • Fewer stars and forks on GitHub, indicating potentially less community support
  • May require more setup and configuration compared to BottomNavigationViewEx

Code Comparison

Material-BottomNavigation:

<it.sephiroth.android.library.bottomnavigation.BottomNavigation
    android:id="@+id/BottomNavigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:bbn_entries="@menu/bottombar_menu"
    app:bbn_badgeProvider="@string/bbn_badgeProvider" />

BottomNavigationViewEx:

<com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx
    android:id="@+id/bnve"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    app:itemIconTint="@color/selector_item_color"
    app:itemTextColor="@color/selector_item_color"
    app:menu="@menu/menu_navigation_with_view_pager" />

Both libraries offer similar functionality, but Material-BottomNavigation provides more built-in features aligned with Material Design, while BottomNavigationViewEx focuses on simplicity and ease of use. The choice between them depends on specific project requirements and the desired level of customization.

Yet another material bottom bar library for Android

Pros of ReadableBottomBar

  • More customizable appearance with text and icon animations
  • Simpler API for adding and managing menu items
  • Lightweight and focused solely on bottom navigation

Cons of ReadableBottomBar

  • Less feature-rich compared to BottomNavigationViewEx
  • May require more manual setup for advanced functionality
  • Limited documentation and community support

Code Comparison

ReadableBottomBar:

val bottomBar = findViewById<ReadableBottomBar>(R.id.bottomBar)
bottomBar.addItem(ReadableBottomBar.Item("Home", R.drawable.ic_home))
bottomBar.addItem(ReadableBottomBar.Item("Search", R.drawable.ic_search))

BottomNavigationViewEx:

val bottomNavView = findViewById<BottomNavigationViewEx>(R.id.bottomNavView)
bottomNavView.enableAnimation(false)
bottomNavView.enableShiftingMode(false)
bottomNavView.enableItemShiftingMode(false)

ReadableBottomBar offers a more straightforward approach to adding items and customizing appearance, while BottomNavigationViewEx provides more granular control over animations and shifting modes. BottomNavigationViewEx extends the official BottomNavigationView, offering additional features and compatibility with Material Design guidelines. ReadableBottomBar, on the other hand, is a custom implementation focused on simplicity and readability.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

中文版点我

BottomNavigationViewEx

An android lib for enhancing BottomNavigationView.

MIT License api 9+

Donator

InfoAmount
Linsong Wang100$

Features

MethodDescription
enableAnimationEnable or disable click item animation(text scale and icon move animation in no item shifting mode). Default true.
enableItemShiftingModeEnable the shifting mode for each item. It will have a shifting animation for item if true. Otherwise the item text is always shown. Default true when item count > 3.
enableShiftingModeEnable the shifting mode for navigation. It will has a shift animation if true. Otherwise all items are the same width. Default true when item count > 3.
getBottomNavigationItemViewGet private mButton in mMenuView at position
getBottomNavigationItemViewsGet private mButtons in mMenuView
getCurrentItemGet the current checked item position.
getIconAtGet icon at position.
getItemCountGet item count.
getItemHeightGet item height.
getLargeLabelAtGet large label at position. Each item has two labels, one is large, the other is small.
getSmallLabelAtGet small label at position. Each item has two labels, one is large, the other is small.
getMenuItemPositionGet menu item position in menu. Return position if success, -1 otherwise.
getOnNavigationItemSelectedListenerGet OnNavigationItemSelectedListener.
setCurrentItemSet the currently checked item.
setIconMarginTopset margin top for icon.
setIconSizeSet all item ImageView size.
setIconSizeAtSet all item ImageView size which is at position.
setIconsMarginTopset margin top for all icons.
setIconTintListSet item icon tint list.
setIconVisibilityChange the visibility of an icon.
setItemBackgroundSet background of item.
setItemHeightSet menu item height.
setLargeTextSizeSet all item large TextView size. Each item has two labels, one small and one large. The small one will be shown when item state is normal. The large one will be shown when item is checked.
setSmallTextSizeSet all item small TextView size. Each item has two labels, one small and one large. The small one will be shown when item state is normal. The large one will be shown when item is checked.
setTextSizeSet all item large and small TextView size.
setTextTintListSet item TextView color.
setTextVisibilityChange the visibility of text.
setTypefaceset Typeface for all item TextView.
setupWithViewPagerThis method will link the given ViewPager and this BottomNavigationViewEx together so that changes in one are automatically reflected in the other. This includes scroll state changes and clicks.

Example

Style

Attention: Something wrong on Android 4.x

With ViewPager

Add ViewBadger

Center Floating Action Button

Adding to project

Sdk Version

compileSdkVersion >= 25

Importing to project(choose one)

Example for Gradle:

Step 1. Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url "https://jitpack.io" }
		maven { url "https://maven.google.com" }
	}
}

Step 2. Add the dependency

  1. old version support lib is 25 or 26
compile 'com.github.ittianyu:BottomNavigationViewEx:1.2.4'
compile "com.android.support:design:26.+"
  1. new version support lib = 28
implementation 'com.github.ittianyu:BottomNavigationViewEx:2.0.4'
implementation "com.android.support:design:28.0.0"
  1. AndroidX use new version,and add config into gradle.properties
android.useAndroidX=true
android.enableJetifier=true

Manual:

Downloading BottomNavigationViewEx.java and copying it to you project.

Getting started

Adding a custom widget in xml :

<com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx
    android:id="@+id/bnve"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="@color/colorPrimary"
    app:itemIconTint="@color/selector_item_color"
    app:itemTextColor="@color/selector_item_color"
    app:menu="@menu/menu_navigation_with_view_pager" />

Binding view in Activity:

BottomNavigationViewEx bnve = (BottomNavigationViewEx) findViewById(R.id.bnve);

Disable all animations

bnve.enableAnimation(false);
bnve.enableShiftingMode(false);
bnve.enableItemShiftingMode(false);

Custom text and icon size

bnve.setIconSize(widthDp, heightDp);
bnve.setTextSize(sp);

Binding with ViewPager

// set adapter
adapter = new VpAdapter(getSupportFragmentManager(), fragments);
bind.vp.setAdapter(adapter);

// binding with ViewPager
bind.bnve.setupWithViewPager(bind.vp);

Add badge view

  1. Add badge lib
    compile 'q.rorbin:badgeview:1.1.0'
    
  2. Bind bottom view
    // add badge
    addBadgeAt(2, 1);
    
    private Badge addBadgeAt(int position, int number) {
        // add badge
        return new QBadgeView(this)
                .setBadgeNumber(number)
                .setGravityOffset(12, 2, true)
                .bindTarget(bind.bnve.getBottomNavigationItemView(position))
                .setOnDragStateChangedListener(new Badge.OnDragStateChangedListener() {
                    @Override
                    public void onDragStateChanged(int dragState, Badge badge, View targetView) {
                        if (Badge.OnDragStateChangedListener.STATE_SUCCEED == dragState)
                            Toast.makeText(BadgeViewActivity.this, R.string.tips_badge_removed, Toast.LENGTH_SHORT).show();
                    }
                });
    }
    

Other usage in BottomNavigationViewEx

You can see the demo.

Usage in BottomNavigationView

Other usage is the same as official BottomNavigationView. You can click here for detail.

ProGuard

If you are using ProGuard you might need to add the following option:

None Android X

-keep public class android.support.design.widget.BottomNavigationView { *; }
-keep public class android.support.design.internal.BottomNavigationMenuView { *; }
-keep public class android.support.design.internal.BottomNavigationPresenter { *; }
-keep public class android.support.design.internal.BottomNavigationItemView { *; }

Android X

-keep public class com.google.android.material.bottomnavigation.BottomNavigationView { *; }
-keep public class com.google.android.material.bottomnavigation.BottomNavigationMenuView { *; }
-keep public class com.google.android.material.bottomnavigation.BottomNavigationPresenter { *; }
-keep public class com.google.android.material.bottomnavigation.BottomNavigationItemView { *; }

References

The lib is based on BottomNavigationView in Support Library 25 design.

I found it was inflexible when I tried the demo. For example, I couldn't change the currently checked item through code. So I wrote a class to extend it to provide some useful methods.

You have no need to worry about stability, because I minimised the modifications through reflection.

Thanks

Thanks to Adrián Mouly | liaolintao | Luong Vo.

License

MIT License

Copyright (c) 2017 ittianyu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Donate

paypal: admin@ittianyu.com