覆盖主题中的属性 [英] Override an attribute in a theme

查看:109
本文介绍了覆盖主题中的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在为应用程序设计主题时遇到麻烦.我使用Material主题如下

I'm having trouble styling a theme for my app. I use Material theme as following

<style name="Theme.KhoaLuanTotNghiep" parent="Theme.MaterialComponents.DayNight.DarkActionBar">

我想自定义主题,以使操作栏的颜色为白色,标题栏的文本为黑色.我已跟踪继承关系以更改操作栏的颜色,但无法更改标题文本的颜色.这就是我所做的:

I want to custom the theme so that the action bar's color is white and title bar text is black. I have traced the inheritance to change the action bar's color but I cant change the color for the title text. This is what I have done:

扩展操作栏并更改其属性

<style name="Widget.App.ActionBar" parent="Widget.MaterialComponents.ActionBar.Primary">
        <item name="background">@color/white</item>
        <item name="titleTextStyle">@style/TextAppearance.AppCompat.Widget.ActionBar.Title.Black</item>
    </style>

要使用的文字外观:

<style name="TextAppearance.AppCompat.Widget.ActionBar.Title.Black">
    <item name="android:textColor">@color/black</item>
</style>

推荐答案

以您的样式创建以下内容,只更改主要文本颜色.我使用purple_200(以浅紫色为例).

create the following in your styles with just the primary text color changed. I use purple_200 (light purple as an example).

<style name="Theme.MyApp.AppBarOverlay" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar" >

    <item name="android:textColorPrimary">@color/purple_200</item>
</style>

然后在AppToolbar中添加主题.这将更新您的应用栏中的textColor

then in your AppToolbar add the theme in it. This will update textColor in your appbar

<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/Theme.MyApp.AppBarOverlay">

您会看到标题现在是浅紫色",而不是默认的白色"

you can see that the title is now "light purple" instead of the default "white"

这篇关于覆盖主题中的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆