android popup menu text color (AppCompat)

francesco.venica picture francesco.venica · Jul 9, 2014 · Viewed 33.7k times · Source

I need to change text color of a popuo menu but I don't find any way for do this, I can change background of popmenu but not the text, I edit the style.xml in this way:

<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
    <!-- API 14 theme customizations can go here. -->

    <item name="popupMenuStyle">@style/MyPopupMenu</item>
    <item name="android:textAppearanceLargePopupMenu">@style/myPopupMenuTextAppearanceLarge</item>
    <item name="android:textAppearanceSmallPopupMenu">@style/myPopupMenuTextAppearanceSmall</item>
</style>

<style name="MyPopupMenu" parent="@style/Widget.AppCompat.PopupMenu">
    <item name="android:popupBackground">#0F213F</item>
</style>

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

<style name="myPopupMenuTextAppearanceLarge" parent="@style/TextAppearance.AppCompat.Base.Widget.PopupMenu.Large">
    <item name="android:textColor">#ffffff</item>
</style>

where is the mistake?

Answer

Juan Labrador picture Juan Labrador · Mar 2, 2015

In styles.xml

<style name="itemTextStyle.AppTheme" parent="@android:style/TextAppearance.Widget.IconMenu.Item">
        <item name="android:textColor">@drawable/color_item_popup</item>
        <item name="android:textSize">@dimen/text_content</item>
    </style>

and add in AppTheme

<item name="android:itemTextAppearance">@style/itemTextStyle.AppTheme</item>

color_item_popup.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:color="@color/primary_text"/>
    <item android:state_focused="true" android:color="@color/primary_text"/>
    <item android:color="@color/secondary_text"/>
</selector>