class MyQuoteListFragment : Fragment() { // or AppCompatActivity override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setHasOptionsMenu(true) // only required for Fragment } override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { inflater.inflate(R.menu.myquote_list, menu) menu.findItem(R.id.action_sync_google_sheet).also { menuItem -> if (menuItem != null) { menuItem.isVisible = true } } super.onCreateOptionsMenu(menu, inflater) }}
Call activity?.invalidateOptionsMenu()
to refresh menu when the conditions changes.
This is only called once, the first time the options menu is displayed.
This is called right before the menu is shown, every time it is shown.