安卓:选项菜单的外观和图标没有得到显示 [英] Android:Option menu appearance and icon not getting displayed
问题描述
我现在面临的几个问题与Android选项菜单中。
I am facing a few problems with the android option menu.
下面是我的code:
在res文件夹,我创建一个包含menu.xml文件文件,这低于code菜单文件夹:
Inside res folder, i created a menu folder containing menu.xml file with this below code:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:icon="@drawable/green"
android:id="@+id/icon" />
<item
android:id="@+id/text"
android:title="Text"/>
<item
android:id="@+id/icon1"
android:title="Icon and Text"
android:icon="@drawable/icon"/>
</menu>
这是我SimpleOptionMenuActivity.java文件:
And this is my SimpleOptionMenuActivity.java file:
public class SimpleOptionMenuActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater=getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.icon:
Toast.makeText(this, "Icon menu option is clicked", Toast.LENGTH_SHORT).show();
break;
case R.id.text:
Toast.makeText(this, "Text menu option is clicked", Toast.LENGTH_SHORT).show();
break;
case R.id.icon1:
Toast.makeText(this, "Icon and Text menu option is clicked", Toast.LENGTH_SHORT).show();
break;
}
return true;
}
}
1)点击仿真器的菜单按钮,菜单是越来越显示像一个ListView即另一个之上,但我想要的选项出现彼此旁边,3个项目每行,也就是说,如果有四个项目则有将两行(这是通常的,我不知道该如何解释这一正确)。
1) On clicking the menu button of emulator, the menu is getting displayed like a ListView i.e. one above another, but i want the options to appear one beside another, 3 items per row, i.e. if there are four items then there will be two rows (which is usual, i don't know how to explain this properly).
2)是没有得到显示图像。我查了R.java文件,图标是绘制内部类里面present但仍然是没有得到显示在菜单中。
2) The image is not getting displayed. I checked the R.java file, the icon is present inside the drawable inner class but still it's not getting displayed in the menu.
请帮我解决这两个问题。
Please help me to solve the two problems.
推荐答案
问题1:
在AndroidManifest.xml中,找到类似以下内容:
使用-SDK
安卓的minSdkVersion =8
机器人:targetSdkVersion =16
删除了android:targetSdkVersion =16
in the AndroidManifest.xml, find something like the following: " uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" " remove the android:targetSdkVersion="16"
问题2:
我menu.xml文件的文件是这样的:
my menu.xml file like this:
<item android:id="@+id/about"
android:icon="@drawable/about"
android:title="@string/about"
android:showAsAction="ifRoom|withText" />
它的工作原理,显示图像的图标,你可以试试它。
it works, show the image icon, you can try it.
这篇关于安卓:选项菜单的外观和图标没有得到显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!