I generate each option of menu from querying database. Here is my code.
final PopupMenu popupMenu = new PopupMenu(getBaseContext(), v);
SQLiteDatabase db =
If your are using AppCompact-v7 then you can style PopupMenu as below:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="popupMenuStyle">@style/popupMenuStyle</item>
</style>
<style name="popupMenuStyle" parent="Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">@android:color/white</item>
</style>
NOTE: PopMenu always works with Activity Context, not with Application context.
In Style Your Application Theme
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:itemBackground">@color/list_background</item>
<item name="android:itemTextAppearance">@style/MyActionBar.MenuTextStyle</item>
</style>
For Text Appearence
<style name="MyActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">@color/list_item_title</item>
<item name="titleTextStyle">@style/MyActionBarTitle</item>
</style>
<style name="MyActionBarTitle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/list_item_title</item>
</style>
<style name="MyActionBar.MenuTextStyle"
parent="style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/list_item_title</item>
<item name="android:textStyle">normal</item>
<item name="android:textSize">16sp</item>
<item name="android:gravity">center</item>
</style>
And Use App Theme In Menifest like:
<application
android:name="Your Package"
android:allowBackup="true"
android:icon="@drawable/launcher_icon"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
at first define your style for popup menu background in styles.xml file in my case i use this...
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:popupMenuStyle">@style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="@android:style/Widget.PopupMenu">
<item name="android:popupBackground">@android:color/holo_green_light</item>
</style>
here i want to change popup menu background in a specific activity , so apply theme(android:theme="@style/AppTheme") with activity declaration and it's surely working. another important thing to create popup menu using this code PopupMenu popup = new PopupMenu(your activity, viewObj);
if you are using AppCompat theme then use
<style name="PopupMenu" parent="Widget.AppCompat.PopupMenu">
<item name="android:popupBackground">@android:color/black</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="popupMenuStyle">@style/PopupMenu</item>
</style>
otherwise
<style name="AppTheme" parent="android:Theme.Light">
<item name="android:popupMenuStyle">@style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="@android:style/Widget.PopupMenu">
<item name="android:popupBackground">@android:color/white</item>
</style>
Add this to your style.xml file
<style name="PopupMenu" parent="Theme.AppCompat.Light">
<item name="android:popupBackground">@android:color/white</item>
</style>
Set the style on Spinner
<Spinner
android:theme="@style/PopupMenu"
android:popupMenuStyle="@style/PopupMenu"/>
This would work for API level 16+ devices too.
Add PopupMenu theme to your AppTheme:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="popupTheme">@style/PopupMenuTheme</item>
</style>
<style name="PopupMenuTheme" parent="Theme.AppCompat.Light">
<item name="android:background">@android:color/white</item>
</style>
manifest.xml:
<application
...
android:theme="@style/AppTheme">
...
</application>