Android ActivityGroup Menu Problem

后端 未结 5 1560
栀梦
栀梦 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:30

    You need to override the menu methods in the activity group, and call the corresponding methods on the child activity. See this article: How to Create Options Menu on Child Activity inside an ActivityGroup

    public class TestGroup extends ActivityGroup {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            //start child activity
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            return getLocalActivityManager().getCurrentActivity().onCreateOptionsMenu(menu);
        }
    
        @Override
        public boolean onMenuItemSelected(int featureId, MenuItem item) {
            return getLocalActivityManager().getCurrentActivity().onMenuItemSelected(featureId, item);
        }
    }
    

提交回复
热议问题