Android a simple way to dynamically add the menu menu

  • 2020-05-17 06:24:24
  • OfStack

Starting with the menu button, there are three methods involved:

1, onCreateOptionsMenu (Menu menu)
2, onPrepareOptionsMenu (Menu menu)
3, onOptionsItemSelected (MenuItem item)


Method name triggers time
The first time after onCreateOptionsMenu enters Launcher, it is triggered when the MENU button is clicked
There are two cases of onPrepareOptionsMenu: 1. After entering Launcher, MENU button is clicked to trigger onCreateOptionsMenu for the first time; 2. 2. After step 1, it will be triggered every time you click the MENU button
onOptionsItemSelected selects anything inside MENU to trigger


Related articles: