4

我在更改 ActionBar 的颜色时遇到了一些麻烦。我正在使用 AppCompat 库提供支持。其他一切都有效:像背景或选择器......但标题颜色没有改变。

这是我的样式文件:

<resources xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">

    <style name="Theme.Customtitletheme" parent="@style/Theme.AppCompat.Light">
        <item name="actionBarItemBackground">@drawable/selectable_background_customtitletheme</item>
        <item name="android:actionBarItemBackground" tools:targetApi="14">@drawable/selectable_background_customtitletheme</item>
        <item name="popupMenuStyle">@style/PopupMenu.Customtitletheme</item>
        <item name="android:popupMenuStyle" tools:targetApi="11">@style/PopupMenu.Customtitletheme</item>
        <item name="dropDownListViewStyle">@style/DropDownListView.Customtitletheme</item>
        <item name="android:dropDownListViewStyle">@style/DropDownListView.Customtitletheme</item>
        <item name="actionBarTabStyle">@style/ActionBarTabStyle.Customtitletheme</item>
        <item name="android:actionBarTabStyle" tools:targetApi="11">@style/ActionBarTabStyle.Customtitletheme</item>
        <item name="actionDropDownStyle">@style/DropDownNav.Customtitletheme</item>
        <item name="android:actionDropDownStyle" tools:targetApi="11">@style/DropDownNav.Customtitletheme</item>
        <item name="actionBarStyle">@style/ActionBar.Solid.Customtitletheme</item>
        <item name="android:actionBarStyle" tools:targetApi="11">@style/ActionBar.Solid.Customtitletheme</item>
        <item name="actionModeBackground">@drawable/cab_background_top_customtitletheme</item>
        <item name="android:actionModeBackground" tools:targetApi="11">@drawable/cab_background_top_customtitletheme</item>
        <item name="actionModeSplitBackground">@drawable/cab_background_bottom_customtitletheme</item>
        <item name="android:actionModeSplitBackground" tools:targetApi="14">@drawable/cab_background_bottom_customtitletheme</item>
        <item name="actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Customtitletheme</item>
        <item name="android:actionModeCloseButtonStyle" tools:targetApi="11">@style/ActionButton.CloseMode.Customtitletheme</item>
        <item name="actionMenuTextColor">@color/actionbar_text</item>
        <item name="android:actionMenuTextColor" tools:targetApi="11">@color/actionbar_text</item>
    </style>

    <style name="ActionBar.Solid.Customtitletheme" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
        <item name="background">@drawable/ab_solid_customtitletheme</item>
        <item name="android:background">@drawable/ab_background_textured_customtitletheme</item>
        <item name="backgroundStacked">@drawable/ab_stacked_solid_customtitletheme</item>
        <item name="android:backgroundStacked" tools:targetApi="14">@drawable/ab_stacked_solid_customtitletheme</item>
        <item name="backgroundSplit">@drawable/ab_bottom_solid_customtitletheme</item>
        <item name="android:backgroundSplit" tools:targetApi="14">@drawable/ab_background_textured_customtitletheme</item>
        <item name="progressBarStyle">@style/ProgressBar.Customtitletheme</item>
        <item name="android:progressBarStyle">@style/ProgressBar.Customtitletheme</item>
        <item name="titleTextStyle">@style/ActionBar.CustomTitle</item>
        <item name="android:textStyle">@style/ActionBar.CustomTitle</item>
    </style>

    <style name="PopupMenu.Customtitletheme" parent="@style/Widget.AppCompat.Light.PopupMenu">
        <item name="android:popupBackground">@drawable/menu_dropdown_panel_customtitletheme</item>
    </style>

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

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

    <style name="DropDownNav.Customtitletheme" parent="@style/Widget.AppCompat.Light.Spinner.DropDown.ActionBar">
        <item name="android:background">@drawable/spinner_background_ab_customtitletheme</item>
        <item name="android:popupBackground">@drawable/menu_dropdown_panel_customtitletheme</item>
        <item name="android:dropDownSelector">@drawable/selectable_background_customtitletheme</item>
    </style>

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

    <style name="ActionButton.CloseMode.Customtitletheme" parent="@style/Widget.AppCompat.Light.ActionButton.CloseMode">
        <item name="android:background">@drawable/btn_cab_done_customtitletheme</item>
    </style>

    <!-- ActionBar title text -->
    <style name="ActionBar.CustomTitle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@color/actionbar_text</item>
        <!-- The textColor property is backward compatible with the Support Library -->
    </style>

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

</resources>

我还使用了不同的值文件夹,例如 values-v14 或 values-v11,但结果相同。

如果我将父级从“Theme.AppCompat.Light”更改为“Theme.AppCompat.Dark”颜色会发生变化,但是当我想使用一些自定义颜色时它不起作用......

此外,这就是我在清单中使用指定主题的方式:

<activity
    android:name="com.cos.ShareActivity"
    android:label="Share File"
    android:parentActivityName="com.cos.FileManagerActivity"
    android:theme="@style/Theme.Customtitletheme" >

    <!-- Parent activity meta-data to support 4.0 and lower -->
    <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value="com.cos.FileManagerActivity" />
</activity>

我做错了什么,颜色项目被忽略了?

4

1 回答 1

2

在花了这么多时间试图弄清楚之后,我发现这是一个错字……该死……我用android:textStyle的是android:titleTextStyle. 当我输入该行时,IDE 自动建议输入第一个 :(

于 2014-06-04T04:39:07.917 回答