I generate each option of menu from querying database. Here is my code.
final PopupMenu popupMenu = new PopupMenu(getBaseContext(), v);
SQLiteDatabase db =
In the layout where you are giving toolbar, specify theme by app:popupTheme="@style/MyPopupMenu"
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:background="#2196F3"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
style="@style/DrawerArrowStyle"
app:popupTheme="@style/MyPopupMenu">
</android.support.v7.widget.Toolbar>
<style name="AppTheme1" parent= "android:Theme.DeviceDefault">
<item name="android:actionBarPopupTheme">@style/popupNew</item>
</style>
<style name="popupNew" parent="android:ThemeOverlay.Material.Light">
<item name="android:colorBackground">#ffffff</item>
</style>
Add popupMenu style to ur AppTheme:
<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>
manifest.xml:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
.............
</application>
You can use custom layout like this..
PopupMenu pop = new PopupMenu(MainActivity.this, v);
pop.getMenuInflater().inflate(R.menu.main, pop.getMenu());
pop.show();
Design layout how you want..hope this helps..
Please Refer How to style PopupMenu? for more explanation. I was facing the same issue, searched alot but found the solution in the link mentioned.
PopupMenu is created in following way :
PopupMenu popup = new PopupMenu(context, view);
PopupMenu takes the styling of the context which is passed, Passing Activity as the context solved my problem.
Please Add Following lines in style xml file, I hope this will help for material design application. Style.xml
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<!-- To change the popup menu and app text color -->
<item name="android:textColor">@color/colorPrimary</item>
<!-- To change the background of options menu-->
<item name="android:itemBackground">@color/skyBlue</item>
</style>
For more details refer this link http://www.viralandroid.com/2016/01/how-to-change-background-and-text-color-of-android-actionbar-option-menu.html