【问题标题】:change title text color of action bar更改操作栏的标题文本颜色
【发布时间】:2014-12-24 09:50:47
【问题描述】:

我使用 android 动作栏样式生成器来生成动作栏,但我想更改动作栏标题的颜色

这是生成器给我的代码:style.xml

<resources>

<style name="Theme.Example" parent="@style/Theme.AppCompat.Light">
    <item name="actionBarItemBackground">@drawable/selectable_background_example</item>
    <item name="popupMenuStyle">@style/PopupMenu.Example</item>
    <item name="dropDownListViewStyle">@style/DropDownListView.Example</item>
    <item name="actionBarTabStyle">@style/ActionBarTabStyle.Example</item>
    <item name="actionDropDownStyle">@style/DropDownNav.Example</item>
    <item name="actionBarStyle">@style/ActionBar.Solid.Example</item>
    <item name="actionModeBackground">@drawable/cab_background_top_example</item>
    <item name="actionModeSplitBackground">@drawable/cab_background_bottom_example</item>
    <item name="actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Example</item>


</style>

<style name="ActionBar.Solid.Example" parent="@style/Widget.AppCompat.Light.ActionBar.Solid">
    <item name="background">@drawable/ab_solid_example</item>
    <item name="backgroundStacked">@drawable/ab_stacked_solid_example</item>
    <item name="backgroundSplit">@drawable/ab_bottom_solid_example</item>
    <item name="progressBarStyle">@style/ProgressBar.Example</item>
</style>

<style name="ActionBar.Transparent.Example" parent="@style/Widget.AppCompat.Light.ActionBar">
    <item name="background">@drawable/ab_transparent_example</item>
    <item name="progressBarStyle">@style/ProgressBar.Example</item>
</style>

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

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

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

<style name="DropDownNav.Example" parent="@style/Widget.AppCompat.Light.Spinner.DropDown.ActionBar">
    <item name="android:background">@drawable/spinner_background_ab_example</item>
    <item name="android:popupBackground">@drawable/menu_dropdown_panel_example</item>
    <item name="android:dropDownSelector">@drawable/selectable_background_example</item>
</style>

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

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

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

然后我将这些代码添加到它们。

<item name="actionBarStyle">@style/myTheme.ActionBar</item>

<style name="myTheme.ActionBar" parent="@style/Widget.AppCompat.ActionBar.Solid">
    <item name="titleTextStyle">@style/myTheme.ActionBar.Text</item>
</style>

<style name="myTheme.ActionBar.Text" parent="@android:style/TextAppearance">
    <item name="android:textColor">@color/actionBarText</item>
</style>
<color name="actionBarText">#fff</color>

但它不起作用,任何人都可以帮助我吗?

【问题讨论】:

    标签: java android android-actionbar


    【解决方案1】:

    尝试为actionBar Style设置自定义样式,然后更改文本样式

    <style name="myTheme.ActionBar" parent="@style/Widget.AppCompat.ActionBar.Solid">
        <item name="android:actionBarStyle">@style/myTheme.ActionBar.Text</item>
    </style>
    
    <style name="myTheme.ActionBar.Text" parent="@style/Widget.AppCompat.ActionBar.Solid">
        <item name="android:titleTextStyle">@style/actionBarText</item>
    </style>
    
    <style name="actionBarText" parent="@android:style/TextAppearance">
        <item name="android:textColor">@android:color/white</item>
    </style>
    

    【讨论】:

    • 抱歉,ActionBarStyle??你在哪里定义它?
    • 抱歉 ... 编辑了项目 .. myTheme.ActionBar.Text。
    猜你喜欢
    • 2015-12-13
    • 1970-01-01
    • 1970-01-01
    • 2013-04-20
    • 1970-01-01
    • 2023-03-03
    • 2015-02-03
    • 1970-01-01
    • 2012-07-31
    相关资源
    最近更新 更多