Re-using Options menu code

前端 未结 3 630
盖世英雄少女心
盖世英雄少女心 2021-01-05 16:51

Is there a convenient way of showing the same Options menu options in multiple Activities?

Example: In my app, I display a TV Guide in one of three ways.

    <
3条回答
  •  半阙折子戏
    2021-01-05 17:20

    You can encapsulate your action menu in a fragment. In this way you only need to add the fragment in the onCreate menu of your activity.

    You need to call setHasOptionsMenu once the fragment is created. To add the add fragment use a tag instead of a layout id.

提交回复
热议问题