Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change background colour of area behind selected item in Android Bottom Navigation Bar

Is it possible to change the background colour of the particular portion of the bar behind the selected item of the bottom navigation bar or any third party libraries that support this?

Also is it possible to add a highlighted bar along the bottom of the selected item like the image below?

See below screenshot:

Bottom Navigation Bar Sample

like image 603
d199224 Avatar asked Aug 02 '17 23:08

d199224


People also ask

How do I color my navigation bar?

Tap the Gear icon next to Active App on the home screen and you can disable coloring for certain apps, or override the default color if you'd prefer another. If you'd rather keep it at one color, choose Static Color on the home screen. Tap the Gear to select your color. This is all you need to get a colored status bar.

How do I change the order of the bottom navigation bar in Android?

Button order You can also adjust the order of the buttons on the Navigation bar. From Settings, tap Display, and then tap Navigation bar. Make sure Buttons is selected, and then you can choose your desired button setup at the bottom of the screen.


1 Answers

You can use the app:itemBackground attribute of BottomNavigationView to do this. The "selected" view is actually checked, so keep that in mind when you're creating your state list.

Something like this should work:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/blue" android:state_checked="true"/>
    <item android:drawable="@color/gray"/>
</selector>
like image 94
Ben P. Avatar answered Oct 01 '22 01:10

Ben P.