简体   繁体   中英

How do I set up a menu for my application?

I am making an application with multiple options, but am unclear as how to go about setting up a menu that is activated within my main activity, and then returning to the main activity after used. I have looked up various tutorials but still am a bit confused. Help? :)

Thanks.

you can create each menu item as an activity then use this code. Note you will also have to create an xml file for the menu as per http://developer.android.com/guide/topics/ui/menus.html

 //Methods for menu // display the menu when menu botton clicked @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.lightmeter, menu); menu.findItem(R.id.about).setIntent(new Intent(this, about.class)); menu.findItem(R.id.edit).setIntent(new Intent(this, menu.class)); return true; } //methods for menu //StartActivity for selecion @Override public boolean onOptionsItemSelected(MenuItem item) { super.onOptionsItemSelected(item); startActivity(item.getIntent()); return true; } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM