Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android - Why my popup menu is black?

Tags:

android

popup

I'm using built-in android popup menu but the result is this:
enter image description here

PopupMenu popupMenu = new PopupMenu(context, holder.menu);
popupMenu.getMenuInflater().inflate(R.menu.item_menu, popupMenu.getMenu());

and the item_menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/one"
        android:title="item1"/>
    <item
        android:id="@+id/two"
        android:title="item2"/>
    <item
        android:id="@+id/three"
        android:title="item3"/>
</menu>  

and the styles for the theme

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="popupMenuStyle">@style/PopupMenu</item>
</style>

<style name="PopupMenu" parent="Widget.AppCompat.PopupMenu">
    <item name="android:popupBackground">#FFFFFF</item>
</style>
like image 982
Mohsen Shakiba Avatar asked Mar 16 '23 10:03

Mohsen Shakiba


1 Answers

Likely to be the Context type:

Parent of my AppTheme is Theme.AppCompat.Light.DarkActionBar and parent of my activity is AppTheme

// Background = black and textColor = black
PopupMenu popupMenu = new PopupMenu(getBaseContext() , view); // don't use getBaseContext()

// Background = black and textColor = white
PopupMenu popupMenu = new PopupMenu(getApplicationContext() , view); // don't use getApplicationContext()

so you must just use Activity Context:

// Background = light and textColor = dark
PopupMenu popupMenu = new PopupMenu(YourActivity.this , view); // this is ok
like image 68
ultra.deep Avatar answered Mar 23 '23 23:03

ultra.deep