更改Android下拉微调颜色AppCompat

时间:2015-02-23 04:08:02

标签: android xml android-actionbar android-appcompat android-styles

我正在尝试更改actionBar的popupMenu / DropDown颜色:

这就是我所拥有的:

Styles.xml

<style name="Theme.Moy" parent="@style/Theme.AppCompat">
    <item name="colorPrimary">@color/red_moy</item>
    <item name="colorPrimaryDark">@color/red_moy_satus_bar</item>
    <item name="android:popupMenuStyle">@style/PopupMenu.Moy</item>
    <item name="android:actionDropDownStyle">@style/myapp_DropDownNav</item>
    <item name="android:actionBarWidgetTheme">@style/myapp.actionBarWidgetTheme</item>
</style>

<style name="myapp.actionBarWidgetTheme" parent="Theme.Moy">
    <item name="android:spinnerDropDownItemStyle">@style/myapp.Widget.DropDownItem.Spinner</item>
</style>

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

<style name="myapp_DropDownNav" parent="@style/Widget.AppCompat.Spinner.DropDown.ActionBar">
    <item name="background">@drawable/menu_dropdown_panel_moy</item>
    <item name="android:background">@drawable/menu_dropdown_panel_moy</item>
    <item name="android:popupBackground">@drawable/menu_dropdown_panel_moy</item>
    <item name="android:dropDownSelector">@drawable/menu_dropdown_panel_moy</item>
</style>

<style name="myapp.Widget.DropDownItem.Spinner" parent="Widget.AppCompat.DropDownItem.Spinner">
    <item name="android:textAppearance">@style/myapp.TextAppearance.Widget.DropDownItem</item>
</style>

<style name="myapp.TextAppearance.Widget.DropDownItem" parent="TextAppearance.AppCompat.Widget.DropDownItem">
    <item name="android:textColor">@color/gray_background_moy</item>
</style>

Styles.xml values-v14

<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Theme.Moy" parent="@style/Theme.AppCompat">
    <item name="colorPrimary">@color/red_moy</item>
    <item name="colorPrimaryDark">@color/red_moy_satus_bar</item>
    <item name="android:popupMenuStyle">@style/PopupMenu.Moy</item>
    <item name="android:actionDropDownStyle">@style/myapp_DropDownNav</item>
    <item name="android:actionBarWidgetTheme">@style/myapp.actionBarWidgetTheme</item>
</style>

<style name="myapp.actionBarWidgetTheme" parent="Theme.Moy">
    <item name="android:spinnerDropDownItemStyle">@style/myapp.Widget.DropDownItem.Spinner</item>
</style>

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

<style name="myapp_DropDownNav" parent="@style/Widget.AppCompat.Spinner.DropDown.ActionBar">
    <item name="background">@drawable/menu_dropdown_panel_moy</item>
    <item name="android:background">@drawable/menu_dropdown_panel_moy</item>
    <item name="android:popupBackground">@drawable/menu_dropdown_panel_moy</item>
    <item name="android:dropDownSelector">@drawable/menu_dropdown_panel_moy</item>
</style>

<style name="myapp.Widget.DropDownItem.Spinner" parent="Widget.AppCompat.DropDownItem.Spinner">
    <item name="android:textAppearance">@style/myapp.TextAppearance.Widget.DropDownItem</item>
</style>

<style name="myapp.TextAppearance.Widget.DropDownItem" parent="TextAppearance.AppCompat.Widget.DropDownItem">
    <item name="android:textColor">@color/gray_background_moy</item>
</style>

它应该是红色的,但它仍然是深灰色(默认)

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

appcompat-v7中的

Theme.Appcompat V21使用自己的ActionBar属性,即没有android:前缀。将它们编辑为 popupMenuStyle actionDropDownStyle actionBarWidgetTheme