How to change text color and popup menu size in Android?

The color of the text in the pop-up menu does not change even in styles. The background color changes relative to the color in styles.xml, but the text color and text size are not reflected.

//Creating the instance of PopupMenu PopupMenu popup = new PopupMenu(mContext, holder.im_overflow); //Inflating the Popup using xml file popup.getMenuInflater().inflate(R.menu.list_overflow_menu, popup.getMenu()); //registering popup with OnMenuItemClickListener popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if( item.getTitle().equals("Edit")){ callEdit(); } else if( item.getTitle().equals("Export")) { callShare(); } else if( item.getTitle().equals("Delete")) { callDelete(); } return true; } }); popup.show(); 

styles.xml

 <style name="AppBaseTheme" parent="@android:style/Theme.Light.NoTitleBar"> </style> <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <item name="android:popupMenuStyle">@style/PopupMenu</item> </style> <style name="PopupMenu" parent="@android:style/Widget.PopupMenu"> <item name="android:popupBackground">@android:color/white</item> <item name="android:textColor">#FF01F0</item> <item name="android:textSize">12sp</item> </style> 

But this does not change the color of the text.

+8
android popupmenu
source share
1 answer

You can change the size and color of the text by adding this code in styles.xml and use it in the manifest file. It worked for me.

 <style name="AppTheme" parent="AppBaseTheme"> <item name="android:popupMenuStyle">@style/PopupMenu</item> <item name="android:textAppearanceLargePopupMenu">@style/myPopupMenuTextAppearanceLarge</item> <item name="android:textAppearanceSmallPopupMenu">@style/myPopupMenuTextAppearanceSmall</item> </style> <style name="PopupMenu" parent="@android:style/Widget.PopupMenu"> <item name="android:popupBackground">@android:color/white</item> <item name="android:textColor">#FF01F0</item> <item name="android:textSize">12sp</item> </style> <style name="myPopupMenuTextAppearanceSmall" parent="@android:style/TextAppearance.DeviceDefault.Widget.PopupMenu.Small"> <item name="android:textColor">#545656</item> <item name="android:textSize">15sp</item> </style> <style name="myPopupMenuTextAppearanceLarge" parent="@android:style/TextAppearance.DeviceDefault.Widget.PopupMenu.Large"> <item name="android:textColor">#545656</item> <item name="android:textSize">25sp</item> </style> 
+12
source share

All Articles