所以我的布局目录中有这个名为“actionbar_buttons.xml”的 XML 文件:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<item android:id="@+id/action_settings"
android:title="Settings">
</item>
<item android:id="@+id/action_settings2"
android:title="fooo">
</item>
</menu>
在我的 Fragment 类中,我这样调用 inflate 方法:
@Override
public void onCreateOptionsMenu(
Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu( menu, inflater );
inflater.inflate(R.layout.actionbar_buttons, menu);
}
现在 Intellij 提示并告诉我:
Expected resource of type menu less... (Ctrl+F1)
Reports two types of problems:
Supplying the wrong type of resource identifier. For example, when calling Resources.getString(int id), you should be passing R.string.something, not R.drawable.something.
Passing the wrong constant to a method which expects one of a specific set of constants. For example, when calling View#setLayoutDirection, the parameter must be android.view.View.LAYOUT_DIRECTION_LTR or android.view.View.LAYOUT_DIRECTION_RTL.
代码确实有效。我只是对 Intellij 中的那个警告感到恼火,我不确定我是否做错了什么。
最佳答案
只需将xml文件移动到
"menu"
资源目录而不是
"layout"
目录。然后换行
inflater.inflate(R.layout.actionbar_buttons, menu);
与
inflater.inflate(R.menu.actionbar_buttons, menu);
关于android - "Expected resource of type menu"展开 MenuButton 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25392403/