菜单目录丢失 [英] menu directory is missing
问题描述
我是Android中非常新的程序员.我正在尝试在我的应用程序中定义一个动作溢出按钮.从我阅读的内容来看,它涉及到修改menu.xml
文件.
我在应用程序中找不到该文件,并且没有res > menu
目录.
我创建了一个SettingActivity.有什么建议吗?
I'm a very new programmer in Android. I'm trying to define an action overflow button in my app. From what I've read it involves modifying the menu.xml
file.
I cannot find that file in my app and I don't have the res > menu
directory.
I have created a SettingActivity. Any Suggestions?
推荐答案
您可以在res/文件夹中创建菜单目录.在Android Studio的项目视图中,在res
上单击鼠标右键,然后单击新建->"Android资源目录".然后在资源类型"下选择菜单.然后,您可以将文件添加到该新的res/menu目录中,该文件包含这样的菜单项(res/menu/main_menu.xml)
You can create a menu dir in the res/ folder. Right click on res
in the project view in Android Studio and click new -> "Android Resource Directory". Then select menu under "Resource Type". You can then add a file to that new res/menu directory that contains your menu items like this (res/menu/main_menu.xml)
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action"
android:title="@string/action"
app:showAsAction="always" />
</menu>
并确保像这样覆盖MainActivity
类中的onCreateOptionsMenu(Menu menu)
:
And get sure to override the onCreateOptionsMenu(Menu menu)
in the MainActivity
class like this:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu,menu);
return true;
}
这篇关于菜单目录丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!