更改操作栏的文本颜色和大小

时间:2014-08-28 15:11:08

标签: android android-actionbar

我尝试通过样式资源更改操作栏的文字颜色和大小:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="Theme.Example3" parent="@android:style/Theme.Holo.Light">
        <item name="android:actionBarItemBackground">@drawable/selectable_background_example3</item>
        <item name="android:popupMenuStyle">@style/PopupMenu.Example3</item>
        <item name="android:dropDownListViewStyle">@style/DropDownListView.Example3</item>
        <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Example3</item>
        <item name="android:actionDropDownStyle">@style/DropDownNav.Example3</item>
        <item name="android:actionBarStyle">@style/ActionBar.Solid.Example3</item>
        <item name="android:actionModeBackground">@drawable/cab_background_top_example3</item>
        <item name="android:actionModeSplitBackground">@drawable/cab_background_bottom_example3</item>
        <item name="android:actionModeCloseButtonStyle">@style/ActionButton.CloseMode.Example3</item>
    </style>

    <style name="ActionBar.Solid.Example3" parent="@android:style/Widget.Holo.Light.ActionBar.Solid">
        <item name="android:background">@drawable/ab_solid_example3</item>
        <item name="android:backgroundStacked">@drawable/ab_stacked_solid_example3</item>
        <item name="android:backgroundSplit">@drawable/ab_bottom_solid_example3</item>
        <item name="android:progressBarStyle">@style/ProgressBar.Example3</item>
    </style>

    <style name="Theme.Example3.ActionBar.Solid.Example3.TitleTextStyle" parent="@android:style/TextAppearance.Medium">
        <item name="android:textSize">20sp</item>
        <item name="android:textColor">@color/white</item>
    </style>

    <style name="ActionBar.Transparent.Example3" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">@drawable/ab_transparent_example3</item>
        <item name="android:progressBarStyle">@style/ProgressBar.Example3</item>
    </style>

    <style name="PopupMenu.Example3" parent="@android:style/Widget.Holo.Light.ListPopupWindow">
        <item name="android:popupBackground">@drawable/menu_dropdown_panel_example3</item>
    </style>

    <style name="DropDownListView.Example3" parent="@android:style/Widget.Holo.Light.ListView.DropDown">
        <item name="android:listSelector">@drawable/selectable_background_example3</item>
    </style>

    <style name="ActionBarTabStyle.Example3" parent="@android:style/Widget.Holo.Light.ActionBar.TabView">
        <item name="android:background">@drawable/tab_indicator_ab_example3</item>
    </style>

    <style name="DropDownNav.Example3" parent="@android:style/Widget.Holo.Light.Spinner">
        <item name="android:background">@drawable/spinner_background_ab_example3</item>
        <item name="android:popupBackground">@drawable/menu_dropdown_panel_example3</item>
        <item name="android:dropDownSelector">@drawable/selectable_background_example3</item>
    </style>

    <style name="ProgressBar.Example3" parent="@android:style/Widget.Holo.Light.ProgressBar.Horizontal">
        <item name="android:progressDrawable">@drawable/progress_horizontal_example3</item>
    </style>

    <style name="ActionButton.CloseMode.Example3" parent="@android:style/Widget.Holo.Light.ActionButton.CloseMode">
        <item name="android:background">@drawable/btn_cab_done_example3</item>
    </style>

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

</resources>

上面的style.xml包含以下代码部分,它应该更改文本颜色和大小,但在我的操作栏上没有任何内容:

<style name="Theme.Example3.ActionBar.Solid.Example3.TitleTextStyle" parent="@android:style/TextAppearance.Medium">
        <item name="android:textSize">20sp</item>
        <item name="android:textColor">@color/white</item>
    </style>

有什么问题?

谢谢!

2 个答案:

答案 0 :(得分:0)

<item name="android:titleTextStyle">@style/Theme.Example3.ActionBar.Solid.Example3.TitleTextStyle</item>
<style name="ActionBar.Solid.Example3">

中缺少

答案 1 :(得分:0)

问题是你需要从第二个样式块中链接第三个样式块:

<style name="ActionBar.Solid.Example3" parent="@android:style/Widget.Holo.Light.ActionBar.Solid">
    <item name="android:background">@drawable/ab_solid_example3</item>
    <item name="android:backgroundStacked">@drawable/ab_stacked_solid_example3</item>
    <item name="android:backgroundSplit">@drawable/ab_bottom_solid_example3</item>
    <item name="android:progressBarStyle">@style/ProgressBar.Example3</item>

    <item name="android:titleTextStyle">@style/Theme.Example3.ActionBar.Solid.Example3.TitleTextStyle</item>

</style>