2

我正在 Android 上开发,我还没有找到一种方法来更改操作栏中项目的背景颜色。我找到了使用 Sherlock 和 holo 的方法,但我仍然找不到它的工作原理。我正在使用这个 AppCompat 和我的 styles.xml 文件

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

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="actionBarItemBackground">@drawable/selectable_background_apptheme</item>
    <item name="popupMenuStyle">@style/PopupMenu.Apptheme</item>
    <item name="dropDownListViewStyle">@style/DropDownListView.Apptheme</item>
    <item name="actionBarTabStyle">@style/ActionBarTabStyle.Apptheme</item>
    <item name="actionDropDownStyle">@style/DropDownNav.Apptheme</item>
    <item name="actionBarStyle">@style/ActionBar.Solid.Apptheme</item>
    <item name="actionModeBackground">@drawable/cab_background_top_apptheme</item>
    <item name="actionModeSplitBackground">@drawable/cab_background_bottom_apptheme</item>
    <item name="actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Apptheme</item>

    <!-- Light.DarkActionBar specific -->
    <item name="actionBarWidgetTheme">@style/Theme.Apptheme.Widget</item>

    <item name="android:actionBarItemBackground">@drawable/selectable_background_apptheme</item>
    <item name="android:popupMenuStyle">@style/PopupMenu.Apptheme</item>
    <item name="android:dropDownListViewStyle">@style/DropDownListView.Apptheme</item>
    <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Apptheme</item>
    <item name="android:actionDropDownStyle">@style/DropDownNav.Apptheme</item>
    <item name="android:actionBarStyle">@style/ActionBar.Solid.Apptheme</item>
    <item name="android:actionModeBackground">@drawable/cab_background_top_apptheme</item>
    <item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_apptheme</item>
    <item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Apptheme</item>

</style>

<style name="ActionBar.Solid.Apptheme" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="background">@drawable/ab_solid_apptheme</item>
    <item name="backgroundStacked">@drawable/ab_stacked_solid_apptheme</item>
    <item name="backgroundSplit">@drawable/ab_bottom_solid_apptheme</item>
    <item name="progressBarStyle">@style/ProgressBar.Apptheme</item>

    <item name="android:background">@drawable/ab_solid_apptheme</item>
    <item name="android:backgroundStacked">@drawable/ab_stacked_solid_apptheme</item>
    <item name="android:backgroundSplit">@drawable/ab_bottom_solid_apptheme</item>
    <item name="android:progressBarStyle">@style/ProgressBar.Apptheme</item>
</style>

<style name="ActionBar.Transparent.Apptheme" parent="@style/Widget.AppCompat.ActionBar">
    <item name="background">@drawable/ab_transparent_apptheme</item>
    <item name="progressBarStyle">@style/ProgressBar.Apptheme</item>

    <item name="android:background">@drawable/ab_transparent_apptheme</item>
    <item name="android:progressBarStyle">@style/ProgressBar.Apptheme</item>
</style>

<style name="PopupMenu.Apptheme" parent="@style/Widget.AppCompat.PopupMenu">
    <item name="android:popupBackground">@drawable/menu_dropdown_panel_apptheme</item>
</style>

<style name="DropDownListView.Apptheme" parent="@style/Widget.AppCompat.ListView.DropDown">
    <item name="android:listSelector">@drawable/selectable_background_apptheme</item>
</style>

<style name="ActionBarTabStyle.Apptheme" parent="@style/Widget.AppCompat.ActionBar.TabView">
    <item name="android:background">@drawable/tab_indicator_ab_apptheme</item>
</style>

<style name="DropDownNav.Apptheme" parent="@style/Widget.AppCompat.Spinner.DropDown.ActionBar">
    <item name="android:background">@drawable/spinner_background_ab_apptheme</item>
    <item name="android:popupBackground">@drawable/menu_dropdown_panel_apptheme</item>
    <item name="android:dropDownSelector">@drawable/selectable_background_apptheme</item>
</style>

<style name="ProgressBar.Apptheme" parent="@style/Widget.AppCompat.ProgressBar.Horizontal">
    <item name="android:progressDrawable">@drawable/progress_horizontal_apptheme</item>
</style>

<style name="ActionButton.CloseMode.Apptheme" parent="@style/Widget.AppCompat.ActionButton.CloseMode">
    <item name="android:background">@drawable/btn_cab_done_apptheme</item>
</style>

<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Apptheme.Widget" parent="@style/Theme.AppCompat">
    <item name="popupMenuStyle">@style/PopupMenu.Apptheme</item>
    <item name="dropDownListViewStyle">@style/DropDownListView.Apptheme</item>

    <item name="android:popupMenuStyle">@style/PopupMenu.Apptheme</item>
    <item name="android:dropDownListViewStyle">@style/DropDownListView.Apptheme</item>
</style>

</resources>

例如,MEGA 应用程序:

大型应用程序

非常感谢!

4

1 回答 1

4

您需要设置“ActionButton”的样式。

<style name="Widget.AppCompat.ActionButton.AppTheme"
       parent="Widget.AppCompat.Light.Base.ActionButton">
    <item name="android:background">@drawable/your_background</item>
    <item name="background">@drawable/your_background</item>
</style>

<style name="ActionBar.Solid.Apptheme" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    //Add this line
    <item name="actionButtonStyle">@style/Widget.AppCompat.ActionButton.AppTheme</item>

    <item name="background">@drawable/ab_solid_apptheme</item>
    <item name="backgroundStacked">@drawable/ab_stacked_solid_apptheme</item>
    <item name="backgroundSplit">@drawable/ab_bottom_solid_apptheme</item>
    <item name="progressBarStyle">@style/ProgressBar.Apptheme</item>

    //Add this line
    <item name="android:actionButtonStyle">@style/Widget.AppCompat.ActionButton.AppTheme</item>

    <item name="android:background">@drawable/ab_solid_apptheme</item>
    <item name="android:backgroundStacked">@drawable/ab_stacked_solid_apptheme</item>
    <item name="android:backgroundSplit">@drawable/ab_bottom_solid_apptheme</item>
    <item name="android:progressBarStyle">@style/ProgressBar.Apptheme</item>

我应该注意,您使用的 drawable 应该是StateListDrawable

于 2013-12-30T23:01:31.240 回答