Android ActivityGroup Menu Problem

后端 未结 5 1556
栀梦
栀梦 2020-12-30 14:58

I have one problem using ActivityGroup. I have two activities inside an ActivityGroup and both of them use a menu (overriding the onCreateOptionMen

5条回答
  •  佛祖请我去吃肉
    2020-12-30 15:34

    Yet another approach is to create the menu in the ActivityGroup root and then use public boolean onPrepareOptionsMenu(Menu menu) to clear and re-add menu items.

    In ActivityGroup class:

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        //what is the current activity?
        menu.add(0, 0, 0, "holder");
        return true;
    }
    
    @Override
    public boolean onPrepareOptionsMenu(Menu menu)
    {
        //start a new
        menu.clear();
        //add some menu options
        .getLocalActivityManager().getCurrentActivity().onPrepareOptionsMenu(menu);
        return super.onPrepareOptionsMenu(menu);
    }
    

    In Activity:

    @Override
    public boolean onPrepareOptionsMenu(Menu menu)
    { //add menus or inflate here
        return true;
    }
    

提交回复
热议问题