Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the text color and size of a pop up menu in android?

Text color in pop up menu is not changing even changed in styles. Background color is changing with respect to the color in styles.xml but the text color and text size are not reflecting.

//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 it is not changing the text color.

like image 913
Ravitheja Avatar asked Jul 30 '14 12:07

Ravitheja


People also ask

How do I change the text color on the pop up menu in Android?

This example demonstrates how do I change the text color of the menu item in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

How do I change the text color on my Android?

Open your device's Settings app . Text and display. Select Color correction. Turn on Use color correction.

What is pop menu in Android?

A PopupMenu displays a Menu in a modal popup window anchored to a View . The popup will appear below the anchor view if there is room, or above it if there is not. If the IME is visible the popup will not overlap it until it is touched. Touching outside of the popup will dismiss it.


1 Answers

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

<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>
like image 55
Ravitheja Avatar answered Oct 10 '22 05:10

Ravitheja