android popup menu text color (AppCompat)
Asked Answered
H

4

37

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?

Hudspeth answered 9/7, 2014 at 11:52 Comment(3)
Define your styles in AppTheme, instead of AppBaseTheme. AppBaseTheme has own implementations for API levels 11 and 14 by default, which redefined your styles.Wollis
possible duplicate of How to style PopupMenu?Bailey
@ArtjomB. Some overlap but not a duplicate because this question is specifically about AppCompat popups.Replica
K
27
<item name="textAppearanceLargePopupMenu">@style/TextAppearance.AppCompat.Light.Widget.PopupMenu.Large</item>
<item name="textAppearanceSmallPopupMenu">@style/TextAppearance.AppCompat.Light.Widget.PopupMenu.Small</item>

I think that you are using TextAppearance.AppCompat.Base.Widget.PopupMenu. Here is the error, you are using another parent that doesn´t response the current style.

You have to use:

TextAppearance.AppCompat.Light.Widget.PopupMenu.

Katharinakatharine answered 9/7, 2014 at 12:19 Comment(3)
what does this mean? can you edit this so that whatever the OP has done is merged to whatever you intend to be done to resolve the issue?Counterpoise
I cant change font color. Can you update to full answer all require style.Trichloromethane
This is what I did based on this answer and it worked for me, thanks Alfaplus! <style name="OverflowMenuText" parent="TextAppearance.AppCompat.Light.Widget.PopupMenu.Large"> <item name="android:textColor">@color/colorToolbarText</item> </style>Pigheaded
J
53

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>
Jochbed answered 2/3, 2015 at 20:34 Comment(0)
K
27
<item name="textAppearanceLargePopupMenu">@style/TextAppearance.AppCompat.Light.Widget.PopupMenu.Large</item>
<item name="textAppearanceSmallPopupMenu">@style/TextAppearance.AppCompat.Light.Widget.PopupMenu.Small</item>

I think that you are using TextAppearance.AppCompat.Base.Widget.PopupMenu. Here is the error, you are using another parent that doesn´t response the current style.

You have to use:

TextAppearance.AppCompat.Light.Widget.PopupMenu.

Katharinakatharine answered 9/7, 2014 at 12:19 Comment(3)
what does this mean? can you edit this so that whatever the OP has done is merged to whatever you intend to be done to resolve the issue?Counterpoise
I cant change font color. Can you update to full answer all require style.Trichloromethane
This is what I did based on this answer and it worked for me, thanks Alfaplus! <style name="OverflowMenuText" parent="TextAppearance.AppCompat.Light.Widget.PopupMenu.Large"> <item name="android:textColor">@color/colorToolbarText</item> </style>Pigheaded
O
20

In styles.xml:

<style name="PopupMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
    <item name="android:popupBackground">@color/white</item>
</style>

In java:

Context wrapper = new ContextThemeWrapper(getContext(), R.style.PopupMenu); final PopupMenu popupMenu = new PopupMenu(wrapper, view);

Orometer answered 10/1, 2016 at 4:46 Comment(0)
D
3
//In Main Style
<item name="popupMenuStyle">@style/popupMenuStyle</item>
    <item name="android:textAppearanceSmallPopupMenu">@style/myPopupMenuTextAppearanceSmall</item>
    <item name="android:textAppearanceLargePopupMenu">@style/myPopupMenuTextAppearanceLarge</item>


  //In Define part

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

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

  //you may use this background 
 //popup_bg.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
    android:angle="135"
    android:centerColor="#c8232323"
    android:endColor="#c80d0d0d"
    android:startColor="#c8434242"
    android:type="linear" />
</shape>
Demurrage answered 27/10, 2018 at 7:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.