So I've got this XML file in my layout directory called "actionbar_buttons.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>
In my Fragment class I call the inflate method like so:
@Override
public void onCreateOptionsMenu(
Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu( menu, inflater );
inflater.inflate(R.layout.actionbar_buttons, menu);
}
Now Intellij complains and tells me:
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.
The code actually does work. I am just annoyed with that warning in Intellij and I'm not entirely sure if I am doing something wrong.
Just move the xml file to the
"menu"
resource directory instead of the
"layout"
directory. Then change the line
inflater.inflate(R.layout.actionbar_buttons, menu);
With
inflater.inflate(R.menu.actionbar_buttons, menu);
I think it should be like:
@Override
public void onCreateOptionsMenu(
Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu( menu, inflater );
inflater.inflate(R.menu.actionbar_buttons, menu);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With