我想更改材质“组件”主题中的标题栏文本颜色。任何帮助将不胜感激

时间:2020-07-25 15:16:30

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

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

来更改颜色
  <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会使我的应用崩溃。

2 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:0)

假设您没有使用Toolbar,则可以在应用程序主题中添加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>

enter image description here