在膨胀MenuButton时"类型菜单的预期资源"

ste*_*uer 5 android intellij-idea android-fragments

所以我的布局目录中有一个名为"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>
Run Code Online (Sandbox Code Playgroud)

在我的Fragment类中,我调用inflate方法,如下所示:

@Override
public void onCreateOptionsMenu(
        Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu( menu, inflater );
    inflater.inflate(R.layout.actionbar_buttons, menu);
}
Run Code Online (Sandbox Code Playgroud)

现在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.
Run Code Online (Sandbox Code Playgroud)

代码确实有效.我对Intellij的警告感到恼火,我不确定我做错了什么.

Ahm*_*nim 14

只需将xml文件移动到

"菜单"

资源目录而不是

"布局"

目录.然后改变这条线

inflater.inflate(R.layout.actionbar_buttons, menu);
Run Code Online (Sandbox Code Playgroud)

 inflater.inflate(R.menu.actionbar_buttons, menu);
Run Code Online (Sandbox Code Playgroud)