我想在 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
menu.xml 文件的 Location:
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>