问题描述
- android 中菜单创建的问题
-
我想在 android 中创建一个菜单。
我在 res/menu 文件夹中创建文件 menu.xml。<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/menu_bookmark" android:title="Bookmark" /> </menu>
确给出下面的错误:
<item android:id="@+id/menu_bookmark" android:title="Bookmark" />
我想在 Login.java 上实现这个页面,寻找这个页面的方法:
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater menuInflater = getMenuInflater(); menuInflater.inflate(R.menu., menu); return true; }
但是也不能给 R.menu.menu()获取 autosuggest。
错误文本:Description Resource Path Location Type Element type "item" must be followed by either attribute specifications, ">" or "/>". menu.xml /MessageReader/res/menu line 3 Android XML Format Problem Syntax error on token ",", delete this token Login.java /MessageReader/src/com/example/messagereader line 78 Java Problem menu cannot be resolved or is not a field Login.java /MessageReader/src/com/example/messagereader line 78 Java Problem
解决方案
menuInflater.inflate(R.menu., menu);//你看下你这里有问题没?
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater=this.getMenuInflater();
inflater.inflate(R.menu.menu01, menu);
return super.onCreateOptionsMenu(menu);
}
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:title="@string/menu01_i01"
android:icon="@drawable/icon"
/>
<item
android:title="@string/menu01_i02"
android:icon="@drawable/icon"
/>
<item
android:title="@string/menu01_i03"
android:icon="@drawable/icon"
/>
<item
android:title="@string/menu01_i04"
android:icon="@drawable/icon"
/>
</menu>
时间: 2024-12-30 01:23:13