Reputation: 39
If I select the Particular item in bottom navigation, left and right side item's background color has to change. Please help me if anyone having any idea.Thank you in advance
Upvotes: 0
Views: 2455
Reputation: 331
On your BottomNavigationView, inthe XML file, add a property called "app:itemBackground" and set a drawable.
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_nav_view_height"
android:background="@color/white"
app:itemBackground="@drawable/item_bottom_nav"
app:menu="@menu/bottom_navigation" />
Then, create the drawable, giving it a normal drawable and a selected drawable. For the selected item, give it the flag android:state_selected="true" like below:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@drawable/bg_item_bottom_nav_select" />
<item android:drawable="@drawable/bg_item_bottom_nav_deselect"/>
</selector>
The last part it's just create two new drawables (the example code above i called "bg_item_bottom_nav_select" and "bg_item_bottom_nav_deselect"). One for the item selected and another for the item when it's not selected. Customize it like you want.
Hope this helps you! :)
Upvotes: 1