简体   繁体   English

如何为我的应用程序设置菜单?

[英]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 请注意,您还必须根据http://developer.android.com/guide/topics/ui/menus.html为菜单创建xml文件。

 //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; } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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