英文:
I want to change title bar text color in material Components theme. Any help will be greatly appreciated
问题
我尝试设置标题颜色,但已被弃用。我尝试使用以下方法更改颜色:
<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>
如此处所述:https://stackoverflow.com/questions/5861661/actionbar-text-color,但在执行此操作时,整个标题栏颜色会变为白色。
我想要做的只是将我的黑色标题栏文字颜色设置为白色。
我还尝试了这个解决方案:https://stackoverflow.com/questions/23801252/change-color-title-bar,但我正在使用MaterialComponents主题,使用AppCompactThemes会导致我的应用崩溃。
英文:
I tried set title color but it is deprecated. I tried to change color by using
<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>
as mentioned here: https://stackoverflow.com/questions/5861661/actionbar-text-color but the whole Titlebar color changes to white while doing it.
All I want to do is set my Black Title bar text color to white.
I also tried this solution here: https://stackoverflow.com/questions/23801252/change-color-title-bar but I am using the MaterialComponents theme and using AppCompactThemes makes my app crash.
答案1
得分: 4
假设您没有使用 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>
作为另一种选择,您可以...
英文:
Assuming that you are not using a Toolbar
the textcolor used in the ActionBar is based on the attribute android:textColorPrimary
.
You can override it adding in your app theme the actionBarTheme
attribute:
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<item name="actionBarTheme">@style/ThemeOverlay.Actionbar</item>
</style>
with:
<style name="ThemeOverlay.Actionbar" parent="ThemeOverlay.MaterialComponents.ActionBar.Surface" >
<item name="android:textColorPrimary">@color/....</item>
</style>
As alternative you can
答案2
得分: 3
以下是翻译好的内容:
只需将此内容添加到您的基础主题中:
<item name="titleTextColor">@android:color/holo_red_dark</item> //无论什么颜色
例如:
<!-- 基础应用程序主题。 -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- 在此自定义您的主题。 -->
<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>
英文:
just add this to you base theme
<item name="titleTextColor">@android:color/holo_red_dark</item> //whatever color
Eg:
<!-- 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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论