0

I am trying to create a bottomNavigationView for my application. I have ended up creating a BMV which can highlight the menu items( using selectors) when selected just like the below images.

enter image description here

enter image description here

However, I need something like having different colors for different menu items when selected

enter image description here

enter image description here

enter image description here

Is it possible to create something like this using bottomnavigationview?

James Z
  • 12,209
  • 10
  • 24
  • 44
  • try this ans https://stackoverflow.com/a/40326245/8089770 – Vidhi Dave Feb 01 '18 at 07:43
  • @VishvaDave that link really didn't helped me – Ravi teja Talari Feb 01 '18 at 10:03
  • 1
    This is not a duplicate, the other linked stack overflow question answers something already done "I have ended up creating a BMV which can highlight the menu items( using selectors)". What he wants is "having different colors for different menu items when selected" – Quentin G. Mar 12 '18 at 22:21
  • 1
    Take a look at that, it does what you want + other stuff https://gist.github.com/QuentinGuillout/070521ff3285b3c07b6fab61e6063465 – Quentin G. Mar 13 '18 at 14:42

1 Answers1

0

You can use this third party library, I have used it before. It is easy, efficient and provides lots of customization.

https://github.com/aurelhubert/ahbottomnavigation

Gradle

dependencies {
    compile 'com.aurelhubert:ahbottomnavigation:2.1.0'
}

XML

<com.aurelhubert.ahbottomnavigation.AHBottomNavigation
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

Activity/Fragment

AHBottomNavigation bottomNavigation = (AHBottomNavigation) findViewById(R.id.bottom_navigation);

// Create items
AHBottomNavigationItem item1 = new AHBottomNavigationItem(R.string.tab_1, R.drawable.ic_maps_place, R.color.color_tab_1);
AHBottomNavigationItem item2 = new AHBottomNavigationItem(R.string.tab_2, R.drawable.ic_maps_local_bar, R.color.color_tab_2);
AHBottomNavigationItem item3 = new AHBottomNavigationItem(R.string.tab_3, R.drawable.ic_maps_local_restaurant, R.color.color_tab_3);

// Add items
bottomNavigation.addItem(item1);
bottomNavigation.addItem(item2);
bottomNavigation.addItem(item3);

// Set background color
bottomNavigation.setDefaultBackgroundColor(Color.parseColor("#FEFEFE"));

// Disable the translation inside the CoordinatorLayout
bottomNavigation.setBehaviorTranslationEnabled(false);

// Enable the translation of the FloatingActionButton
bottomNavigation.manageFloatingActionButtonBehavior(floatingActionButton);

// Change colors
bottomNavigation.setAccentColor(Color.parseColor("#F63D2B"));
bottomNavigation.setInactiveColor(Color.parseColor("#747474"));

// Force to tint the drawable (useful for font with icon for example)
bottomNavigation.setForceTint(true);

// Display color under navigation bar (API 21+)
// Don't forget these lines in your style-v21
// <item name="android:windowTranslucentNavigation">true</item>
// <item name="android:fitsSystemWindows">true</item>
bottomNavigation.setTranslucentNavigationEnabled(true);

// Manage titles
bottomNavigation.setTitleState(AHBottomNavigation.TitleState.SHOW_WHEN_ACTIVE);
bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_SHOW);
bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_HIDE);

// Use colored navigation with circle reveal effect
bottomNavigation.setColored(true);

// Set current item programmatically
bottomNavigation.setCurrentItem(1);

// Customize notification (title, background, typeface)
bottomNavigation.setNotificationBackgroundColor(Color.parseColor("#F63D2B"));

// Add or remove notification for each item
bottomNavigation.setNotification("1", 3);
// OR
AHNotification notification = new AHNotification.Builder()
    .setText("1")
    .setBackgroundColor(ContextCompat.getColor(DemoActivity.this, R.color.color_notification_back))
    .setTextColor(ContextCompat.getColor(DemoActivity.this, R.color.color_notification_text))
     .build();
bottomNavigation.setNotification(notification, 1);

// Enable / disable item & set disable color
bottomNavigation.enableItemAtPosition(2);
bottomNavigation.disableItemAtPosition(2);
bottomNavigation.setItemDisableColor(Color.parseColor("#3A000000"));

// Set listeners
bottomNavigation.setOnTabSelectedListener(new AHBottomNavigation.OnTabSelectedListener() {
    @Override
    public boolean onTabSelected(int position, boolean wasSelected) {
        // Do something cool here...
        return true;
    }
});
bottomNavigation.setOnNavigationPositionListener(new AHBottomNavigation.OnNavigationPositionListener() {
    @Override public void onPositionChange(int y) {
        // Manage the new y position
    }
});

For more info check above link I have provided. Hope this helps

Rahul Singh Chandrabhan
  • 2,531
  • 5
  • 22
  • 33