Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Option Menu stays empty white in Android [closed]

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...

like image 601
jellyfish Avatar asked Feb 04 '26 21:02

jellyfish


1 Answers

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

like image 125
Anton Derevyanko Avatar answered Feb 06 '26 10:02

Anton Derevyanko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!