Selected Tab's Color in Bottom Navigation View

Selected tab's color in Bottom Navigation View

While making a selector, always keep the default state at the end, otherwise only default state would be used. You need to reorder the items in your selector as:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="@android:color/holo_blue_dark" />
<item android:color="@android:color/darker_gray" />
</selector>

And the state to be used with BottomNavigationBar is state_checked not state_selected.

Selected Item in BottomNavigationView Has Same Color as Background

You need to make drawable selector for your bottom navigation view, here is the example (nav_item_color_state.xml)

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/white" android:state_checked="true" />
<item android:color="@color/darker_gray" android:state_checked="false" />
</selector>

then add codes below to your bottom navigation view

app:itemIconTint="@drawable/nav_item_color_state"
app:itemTextColor="@drawable/nav_item_color_state"

different background color to bottom navigation tab selected item by using material design

Ok, Some curious thing i found is you cannot have background color and text/icon color style on same file.

so u need two files

bottom_navigation_style.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:color="@color/colorPrimary" android:state_selected="true" />
<item android:color="@android:color/darker_gray" android:state_selected="false" />

</selector>

bottom_navigation_style_background.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@color/colorPrimaryDark" android:state_checked="true" />
<item android:drawable="@android:color/white" android:state_checked="false" />

</selector>

Then on activity xml you need to add to itemBackground like this

 app:itemBackground="@drawable/bottom_navigation_style_background"
app:itemIconTint="@drawable/bottom_navigation_style"
app:itemTextColor="@drawable/bottom_navigation_style"

It will work for sure.

Android BottomNavigationView One tab with different unselected/selected colors

BottomNavigationView is painfully more difficult than its iOS implementation. I did some research to see if what you were asking was possible, and then when I saw it in Android native, I started thinking of ways to make it happen.

To implement your last challenge, you would have to programmatically change the selected tint/color every time depending on the index of the bottom navigation view.

How to change the icon color selected on bottom navigation bar in android studio

To change the selected tab icon color in BottomNavigationView you should use the Selector.

Create bottom_navigation_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="@color/yourSelectedColor" />
<item android:color="@color/defaultColor" />
</selector>

Apply app:itemIconTint="@drawable/bottom_navigation_selector" to your BottomNavigationView in xml file.

How to add a different background color to bottom navigation tab selected item?

this library can help you

NavigationTabBar

in gradle(app)

compile 'devlight.io:navigationtabbar:1.2.5'

simply add this in your xml file

 <devlight.io.library.ntb.NavigationTabBar
android:id="@+id/navigationTabBar"
android:layout_width="match_parent"
android:layout_height="@dimen/_50sdp"
app:ntb_animation_duration="400"
app:ntb_titled="true"
app:ntb_scaled="true"
app:ntb_tinted="true"
app:ntb_bg_color="@color/colorPrimary"
app:ntb_active_color="@color/colorAccent"
app:ntb_inactive_color="@color/colorPrimary"
app:ntb_title_mode="all"
app:ntb_swiped="true"
app:ntb_icon_size_fraction="0.4"
app:ntb_title_size="@dimen/littleFontSize"/>

UPDATE

you can create selector name backgrand_nav_item.xml like below

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/colorAccent"
android:state_checked="true"/>
<item android:drawable="@color/colorPrimary"
android:state_checked="false"/>
</selector>

and your BottomNavigationView

<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation_Userview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:itemBackground="@drawable/backgrand_nav_item"
app:itemIconTint="@drawable/navigation_item_selector"
app:itemTextColor="@drawable/navigation_item_selector"
app:menu="@menu/navigation1"/>

Why does BottomNavigationView not changing selected tab Icon?

You have to return true in the onNavigationItemSelected method:

    @Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
...
return true;
}

You can check the doc:

Returns

boolean true to display the item as the selected item and false if the item should not be selected. Consider setting non-selectable items as disabled preemptively to make them appear non-interactive.

Also you are using app:labelVisibilityMode="unlabeled".

It means that the label is hidden for all navigation items (LABEL_VISIBILITY_UNLABELED)



Related Topics



Leave a reply



Submit