-1
I would like to add dynamically options to my screen menu on Android, I saw several examples, but all facing a single button.
supposing that I have.
override fun onCreateOptionsMenu(menu: Menu, menuInflater: MenuInflater) {
menu.clear()
val menu1 = menu
.add(Menu.NONE, 1, Menu.NONE, null)
.setIcon(R.drawable.ic_add_round_white)
.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM)
val menu2 = menu
.add(Menu.NONE, 2, Menu.NONE, null)
.setIcon(R.drawable.ic_edit_white)
.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM)
}
in this example I can generate 2 buttons to the top bar of my screen, the doubt is how to increment options within these buttons?
I use Kotlin, but java would already solve.
It is not better you create the layout on
menu.xml
and overwrite the methodonPrepareOptionsMenu
changing only the visibility of the items you want to appear?– Eduardo Dornel
No, because the options are based on what the API provides me, which can change dynamically ;(
– Belita Colares