android popup menu text color (AppCompat)

后端 未结 4 588
没有蜡笔的小新
没有蜡笔的小新 2020-12-01 20:40

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:

相关标签:
4条回答
  • 2020-12-01 21:08

    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);

    0 讨论(0)
  • 2020-12-01 21:12
    //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>
    
    0 讨论(0)
  • 2020-12-01 21:14
    <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.

    0 讨论(0)
  • 2020-12-01 21:26

    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>
    
    0 讨论(0)
提交回复
热议问题