I am using Bottom NavigationView and want to change items programmatically. There are 5 items and when I set 4th item selected, First item still remains active.
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="@color/color_white"
app:itemIconTint="@color/drawer_item"
app:itemTextColor="@color/drawer_item"
android:layout_gravity="start"
app:menu="@menu/nav_bar_menu"/>
From API 25.3.0,
you can use setSelectedItemId
BottomNavigationView bottomNavigationView;
bottomNavigationView = (BottomNavigationView)findViewById(R.id.bottom_navigation);
bottomNavigationView.setSelectedItemId(R.id.item_4th);
There is no possible way to change items through code currently but found the solution here Set initially selected item index/id in BottomNavigationView
This worked for me Saved me playing with fragments
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.getMenu().findItem(R.id.my_navigation_item).setChecked(true);
navigationView.getMenu().performIdentifierAction(R.id.my_navigation_item, 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With