Option Menu:
<item
android:id="@+id/home"
android:icon="@drawable/ic_home"
android:title="Home"/>
<item
android:id="@+id/companies"
android:icon="@drawable/ic_companies"
android:title="Companies"/>
<item
android:id="@+id/contact"
android:icon="@drawable/ic_contacts"
android:title="Contact"/>
I want to change this item's icon programmatically depending on the open Fragment and, obviously, have different actions when the user hits this button. I tried several things to do that, but nothing worked.
The last thing I tried was this code in my Fragment
onCreateView
method:
Menu menu = bottomNavigationView.getMenu();
menu.findItem(R.id.ic_home).setIcon(R.drawable.ic_home_fill);
but its not work for me.
what i tried in selectFragment(MenuItem item)
switch (item.getItemId()) {
case R.id.home:
item.setIcon(R.id.ic_home_fill);
break;
}
I want to change the icon of the bottom navigation of selected position. if user clicked one item then the icon change to another one and when i select another one then 1st icon can set as a default.
refer this link:Android: Bottom Navigation View - change icon of selected item but it's not work for me
plz give me a other solution.
Thank you