我有以下布局xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<item android:id="@+id/descriptions_menu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:icon="@drawable/ic_menu_info_details"
android:title="Toggle Descriptions On/ Off" />
<item android:id="@+id/settings_menu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:icon="@drawable/ic_menu_preferences"
android:title="Settings" />
但我一直收到这个错误: 缺少必需的layout_width和layout_height属性
这是在第2,9,10行报道的。这看起来很奇怪。它是一个旧项目(> 5年),我试图复活。
答案 0 :(得分:15)
我认为menu
布局在res/layout
中无效,您需要按documentation
res/menu
中
对其进行充气要定义菜单,请在项目的 res / menu / 目录中创建XML文件,并使用以下元素构建菜单
答案 1 :(得分:3)
如果这是菜单文件,则必须关闭文件末尾的菜单标签, 确保此文件位于res&gt;菜单文件夹&gt;菜单文件。
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<item android:id="@+id/descriptions_menu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:icon="@drawable/ic_menu_info_details"
android:title="Toggle Descriptions On/ Off" />
<item android:id="@+id/settings_menu"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:icon="@drawable/ic_menu_preferences"
android:title="Settings" />
</menu>