在Android中创建选项菜单 [英] Creating Options menu in Android
本文介绍了在Android中创建选项菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的Android程序来创建选项菜单。我使用下面的code夸大选项菜单:
I am trying to create options menu in my Android program. I am using the following code to inflate options menu :
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater=getMenuInflater();
inflater.inflate(R.menu.optionsmenu, menu);
return true;
}
和我的XML code是:
And my xml code is :
?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/Option1"
android:title="Option1"/>
<item
android:id="@+id/Option2"
android:title="Option2"/>
<item
android:id="@+id/Option3"
android:title="Option3"/>
</menu>
但有了这个code我不能够显示的选项菜单中我的屏幕。
But with this code i am not able to show the options menu in my screen.
另外,我现在用的是code
Also, i am using the code
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
,使活动为全屏视图。这是否code在充气菜单创建问题?
to make the activity as full screen view. Does this code creates problem in inflating the menu?
由于提前,
Timson
推荐答案
删除行 super.onCreateOptionsMenu(菜单);
从onCreateOptionMenu。你实际上已经膨胀之前提供的菜单。
remove the line super.onCreateOptionsMenu(menu);
from your onCreateOptionMenu. You are actually already providing the menu before inflating it.
这篇关于在Android中创建选项菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文