0

How to Change PopupMenu Text Color in Android?

I googled and got the below code but its not worked in my case.

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
         <item name="android:popupMenuStyle">@style/popupMenuStyle</item> 
        <item name="android:textAppearanceSmallPopupMenu">@style/myPopupMenuTextAppearanceSmall</item>
    </style>

   <style name="myPopupMenuTextAppearanceSmall" parent="@android:style/TextAppearance.DeviceDefault.Widget.PopupMenu.Small">
       <item name="android:textColor">#FFFFFF</item>
   </style>

     <style name="popupMenuStyle" parent="@android:style/Widget.PopupMenu">
        <item name="android:popupBackground">@drawable/bg_trans_popup</item>
        <item name="android:textColor">#FFFFFF</item>
    </style> 

and Programatically,

 //Creating the instance of PopupMenu  
                PopupMenu popup = new PopupMenu(Registration.this, v);  

                //Inflating the Popup using xml file  
                popup.getMenuInflater().inflate(R.menu.main, popup.getMenu());  

                //registering popup with OnMenuItemClickListener  
                popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {  
                 public boolean onMenuItemClick(MenuItem item) {  
//                Toast.makeText(MainActivity.this,"You Clicked : " + item.getTitle(),Toast.LENGTH_SHORT).show();  
                  return true;  
                 }  
                });  

                popup.show();

and menu file : main.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/menu_roomservices"
        android:icon="@drawable/ic_launcher"
        android:title="Room Services"/>

</menu>

So, Please suggest me on this?

Polam Naganji
  • 277
  • 7
  • 19

1 Answers1

0

You can do it dynamically when you get the textView or the exact view where is your text and to set its color (or their color, when you want to change it to the whole popup menu). You can use for example: textView.setTextColor(Color.parseColor("#FFFFFF"));

Gabriella Angelova
  • 2,985
  • 1
  • 17
  • 30
  • I Updated Dynamic Code. So, Please suggest me where i need to add this line? – Polam Naganji Apr 22 '15 at 04:28
  • Can you please share your menu.main.xml code? You should set the color to a specific view in the layout of the menu. – Gabriella Angelova Apr 22 '15 at 06:26
  • this is my main.xml code – Polam Naganji Apr 22 '15 at 06:45
  • hm... so it won't happen as I thought... Did you add your popup style definitions to your app theme file. Maybe you need to add there something like: `` as it is shown in the second answer here: http://stackoverflow.com/questions/12636101/how-to-style-popupmenu – Gabriella Angelova Apr 22 '15 at 07:24