how to create a common menu for an android application
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.
精彩评论