Static options menu

后端 未结 1 1745
野性不改
野性不改 2021-01-03 06:01

I want to create a static options menu for all my activity screens. I dont want to override onCreateOptionsMenu() in each activity.

Since Menu

相关标签:
1条回答
  • 2021-01-03 06:45

    If I read your question correctly you want the same menu in all your Activities. I can think of two ways to do this:

    1. Create a subclass of Activity that implements onCreateOptionsMenu() and onOptionsItemSelected() (and possibly onPrepareOptionsMenu). Then have all your Activity classes extend this subclass.

    2. Create a static method somewhere called something like populateOptionsMenu() that takes a Menu (and probably a Context) as arguments. Your Activity classes can then call this from their onCreateOptionsMenu() methods to populate the Menu. You'd also need a corresponding processItemSelected() static method for when items were clicked.

    Option 1 seems best as it wouldn't require the same bolierplate in your Activities to call the static methods.

    0 讨论(0)
提交回复
热议问题