开发者

how to create a common menu for an android application

开发者 https://www.devze.com 2023-03-13 03:54 出处:网络
For an开发者_如何转开发 android application I need to have a single menu in common that can be displayed on every screen with its structure and functionality written in another class or activity that

For an开发者_如何转开发 android application I need to have a single menu in common that can be displayed on every screen with its structure and functionality written in another class or activity that can be used in all other activities.


Create baseClass Activity. There you can implement the menu structure. After that each activity extends this baseClass activity.


Create a MainActivity which extends ActivityGroup class and all other activity as its sub activities . Use onCreateOptionsMenu(Menu menu) method to addmenu item in MainActivity. All the other activity can show that menu items automatically.

see this:

public class MainActivity extends ActivityGroup {

 @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // TODO Auto-generated method stub
        menu.add("1");
        menu.add("2");
        return super.onCreateOptionsMenu(menu);
    }

  @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        //start other activity here
    }
}

Hope this will give you some idea on the issue.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号