Amando Arkan
Amando Arkan

Reputation: 35

how to hide/remove icon menu items in actionbar when moving bottomnavigation kotlin?

in actionbar home fragment bottomnavigation

enter image description here

in action bar favorite fragment bottomnavigation

enter image description here

how to hide or remove actionbar icon when moving to favorite fragment?

Upvotes: 1

Views: 328

Answers (1)

mightyWOZ
mightyWOZ

Reputation: 8335

You just need to make your FavoriteFragment options menu aware and then in onCreateOptionsMenu, simply clear the menu. this can be done by updating FavoriteFragment with following changes

In onCreateView, call setHasOptionsMenu(true) to receive options menu related callbacks in Fragment

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
    // Allows your fragment to receive options menu related callbacks (onCreateOptionsMenu etc)
    setHasOptionsMenu(true)
    ...
}

now override onCreateOptionsMenu and clear the already populated menu as

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
    super.onCreateOptionsMenu(menu, inflater)
    menu.clear()
}

Upvotes: 3

Related Questions