I am trying to add an item in a bottom menu navigation bar according to a var got from an API.
I am able to delete an item from this navigation bar, like this :
if (restaurant.acceptsBookings == false) {
bottom_navigation_view.menu.removeItem(R.id.bottom_menu_book)
}
The problem is, when I am launching my app, we can see the icon during like, half of a second, then it disappears.
This is not that bad, but I was hoping there is a better and neater way to do this ; for example by adding the elements in an empty navigation bar, instead of removing them.
Here is my navigation bar xml code :
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/bottom_menu_home"
android:enabled="true"
android:title="@string/bottom_menu_home"
android:icon="@drawable/ic_home"
app:showAsAction="ifRoom" />
<item
android:id="@+id/bottom_menu_menu"
android:enabled="true"
android:icon="@drawable/ic_menu"
android:title="@string/bottom_menu_menu"
app:showAsAction="ifRoom" />
<item
android:id="@+id/bottom_menu_profile"
android:enabled="true"
android:title="@string/bottom_menu_profile"
android:icon="@drawable/ic_user"
app:showAsAction="ifRoom" />
<item
android:id="@+id/bottom_menu_book"
android:enabled="true"
android:icon="@android:drawable/ic_menu_my_calendar"
android:title="@string/bottom_menu_bookings"
app:showAsAction="ifRoom" />
<item
android:id="@+id/bottom_menu_fidelity"
android:enabled="true"
android:icon="@drawable/giftgrey2"
android:title="@string/bottom_menu_fidelity"
app:showAsAction="ifRoom" />
</menu>
Do someone have a solution for this ?
Thanks in advance.