【问题标题】:I want to change title bar text color in material Components theme. Any help will be greatly appreciated我想更改材质组件主题中的标题栏文本颜色。任何帮助将不胜感激
【发布时间】:2020-11-15 06:58:15
【问题描述】:

我尝试设置标题颜色,但已弃用。我试图通过使用来改变颜色

  <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>
  </style>

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

如此处所述:ActionBar text color 但在执行此操作时整个标题栏颜色变为白色。 我要做的就是将我的黑色标题栏文本颜色设置为白色。 我也在这里尝试了这个解决方案:Change color title bar 但我使用的是 MaterialComponents 主题,并且使用 AppCompactThemes 会使我的应用崩溃。

【问题讨论】:

    标签: java android android-actionbar material-components-android material-components


    【解决方案1】:

    只需将此添加到您的基本主题

     <item name="titleTextColor">@android:color/holo_red_dark</item> //whatever color
    

    例如:

    <!-- Base application theme. -->
        <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
            <!-- Customize your theme here. -->
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
            <item name="titleTextColor">@android:color/holo_green_dark</item>
    
        </style>
    

    【讨论】:

    • 工作就像魅力!简单实用
    【解决方案2】:

    假设您没有使用Toolbar,ActionBar 中使用的文本颜色基于属性android:textColorPrimary
    您可以覆盖它,在您的应用主题中添加 actionBarTheme 属性:

    <style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
        <item name="actionBarTheme">@style/ThemeOverlay.Actionbar</item>
    </style>
    

    与:

    <style name="ThemeOverlay.Actionbar" parent="ThemeOverlay.MaterialComponents.ActionBar.Surface" >
            <item name="android:textColorPrimary">@color/....</item>
    </style>
    

    你也可以

    【讨论】:

    • 即使您的答案可能正确且有效,但我更喜欢@notTdar 提供的简单解决方案
    猜你喜欢
    • 1970-01-01
    • 2015-10-06
    • 1970-01-01
    • 2021-01-07
    • 2021-10-21
    • 2018-10-12
    • 2019-08-06
    • 2019-06-03
    • 2016-08-20
    相关资源
    最近更新 更多