3

I just tried to add an option menu to my app, but it's not showing any content.

Here's my XML:

<menu xmlns:android="https://schemas.android.com/apk/res/android">

    <item android:id="@+id/item1" 
        android:title="Test1"/>
    
    <item android:id="@+id/item2" 
        android:title="Test2"/>
        
    <item android:id="@+id/item3" 
        android:title="Test3" 
        android:icon="@drawable/icon"/>

</menu>

Path is res/menu/menu.xml

That's my code in the main activity:

public boolean onCreateOptionsMenu(Menu menu){

    MenuInflater inflater = getMenuInflater();

    inflater.inflate(R.menu.menu, menu);

    return true;
}

I can open the menu and it shows three white squares. I can click on them and the menu closes.

I tried changing the text color via android:textColor and the background color via android:color, but this didn't work either.

Edit: It's working if I use menu.add(...), but I actually do prefer using the XML resource...

bad_coder
  • 11,289
  • 20
  • 44
  • 72
jellyfish
  • 7,868
  • 11
  • 37
  • 49

1 Answers1

3

You should change <menu xmlns:android="https://schemas.android.com/apk/res/android"> to <menu xmlns:android="http://schemas.android.com/apk/res/android">

Anton Derevyanko
  • 3,405
  • 1
  • 24
  • 32