16

我希望自定义我的 android 应用程序的 actionBar。
我正在使用 Actionbar Sherlock。
我的最小目标 sdk 是 14,目标 sdk 17。
我有一个更改背景颜色和主标题文本的主题,
但是我无法更改字幕文本颜色
我的样式显示在这里

<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
</style>

<style name="MyTheme.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
    <item name="android:background">#8B0000</item>
</style>

<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">#FFFFFF</item>

</style>

<style name="MyTheme.ActionBar.Subtitle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Subtitle">
    <item name="android:textColor">#FF0000</item>

</style>


做错了什么?

4

7 回答 7

21

只需更改titleTextStylesubtitleTextStyle

<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
  </style>

  <style name="MyTheme.ActionBarStyle"parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:subtitleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
  </style>

  <style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">@color/red</item>
  </style>
于 2013-07-04T20:41:52.993 回答
3

这组样式格式化了动作栏,包括背景、标题和副标题文本;它还格式化选项卡,包括所有状态(选中、未选中和所有聚焦/按下的组合),以及选项卡文本字体和大小(根据 Android 开发人员说明https://developer.android.com/training/basics /actionbar/styling.html):

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/themeActionBar</item>
    <item name="android:actionBarTabTextStyle">@style/styleActionBarTabText</item>
    <item name="android:actionMenuTextColor">@color/actionbar_text</item>
    <item name="android:actionBarTabStyle">@style/styleActionBarTabs</item>
    <!-- Support library compatibility -->
    <item name="actionBarStyle">@style/themeActionBar</item>
    <item name="actionBarTabTextStyle">@style/styleActionBarTabText</item>
    <item name="actionMenuTextColor">@color/actionbar_text</item>
    <item name="actionBarTabStyle">@style/styleActionBarTabs</item>
</style>

<!-- ActionBar styles -->
<style name="themeActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@drawable/abactionbargradient</item>
    <item name="android:titleTextStyle">@style/styleActionBarTitleText</item>
    <item name="android:subtitleTextStyle">@style/styleActionBarSubTitleText</item>
    <!-- Support library compatibility -->
    <item name="background">@drawable/abactionbargradient</item>
    <item name="titleTextStyle">@style/styleActionBarTitleText</item>
    <item name="subtitleTextStyle">@style/styleActionBarSubTitleText</item>
</style>

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

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

<!-- ActionBar tabs text -->
<style name="styleActionBarTabText"
    parent="@style/Widget.AppCompat.ActionBar.TabText">
    <item name="android:textColor">@color/actionbar_text</item>
    <item name="android:textSize">10dp</item>
    <!-- The textColor property is backward compatible with the Support Library -->
</style>

<!-- ActionBar tabs styles -->
<style name="styleActionBarTabs"
    parent="@style/Widget.AppCompat.ActionBar.TabView">
    <!-- tab indicator -->
    <item name="android:background">@drawable/abactionbartabs</item>

    <!-- Support library compatibility -->
    <item name="background">@drawable/abactionbartabs</item>
</style>

当可绘制对象是使用一组连贯颜色值的渐变时,这组样式看起来特别好(例如,选定的淡紫色到紫色,未选定的紫色到淡紫色,将值更改为按下时更暗,聚焦时更亮)。

于 2014-07-13T21:56:17.540 回答
3

在您的活动文件中添加以下代码

 actionBar.setSubtitle(Html.fromHtml("<font color='#FFBF00'>Here ActionBar Subtitle</font>"));
于 2016-03-17T05:07:03.873 回答
2

差不多好了。这是代码:

<style name="MyTheme" parent="@android:style/Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
</style>

<style name="MyTheme.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
    <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
    <item name="android:subtitleTextStyle">@style/MyTheme.ActionBar.Subtitle</item>
    <item name="android:background">#8B0000</item>
</style>

<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">#FFFFFF</item>
</style>

<style name="MyTheme.ActionBar.Subtitle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Subtitle">
    <item name="android:textColor">#FF0000</item>
</style>
于 2014-01-17T04:18:37.967 回答
1

示例添加

<android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            android:background="@color/colorPrimary"
            app:titleTextColor="@color/white"
            app:subtitleTextColor="@color/white"
            android:gravity="center"
            >

字幕颜色

        app:subtitleTextColor="@color/white"
于 2018-04-13T15:25:24.180 回答
0

我最终得到了这个(它更接近我需要的东西)

@style/Widget.Styled.ActionBar @style/Widget.Styled.ActionBar

<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.ActionBar.Solid">
    <item name="subtitleTextStyle">@style/TextAppearance.Sherlock.Widget.Styled.ActionBar.Subtitle</item>
    <item name="android:subtitleTextStyle">@style/TextAppearance.Sherlock.Widget.Styled.ActionBar.Subtitle</item>
    <item name="android:background">#8B0000</item>
</style>

<style name="TextAppearance.Sherlock.Widget.Styled.ActionBar.Subtitle" parent="Widget">
    <item name="android:textSize">12sp</item>
</style>

<style name="OverFlow" parent="Widget.Sherlock.ActionButton.Overflow">
    <item name="android:src">@drawable/abs__ic_menu_moreoverflow_holo_light</item>
</style>


于 2013-07-04T20:48:42.330 回答
0

步:

1) 通过 id 包含操作栏

2)检查操作栏是否存在(不为空)

3)检查apk版本

4) 更改字幕的文字颜色和背景颜色

Toolbar actionBarToolbar = (Toolbar) findViewById(R.id.action_bar); //change R.id.action_bar with your action bar id

       if (actionBarToolbar != null) // check if action bar is not null

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // check version of apk

         actionBarToolbar.setBackgroundColor(getResources().getColor(R.color.colorPrimary)); // change actionBarToolbar background color

         actionBarToolbar.setSubtitleTextColor(Color.WHITE); // finally  this line change subtitle text color

        }
于 2019-08-12T16:17:55.083 回答