android - 覆盖主题中的属性
问题描述
我在为我的应用程序设计主题时遇到问题。我使用 Material 主题如下
<style name="Theme.KhoaLuanTotNghiep" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
我想自定义主题,使操作栏的颜色为白色,标题栏文本为黑色。我已经跟踪了更改操作栏颜色的继承,但我无法更改标题文本的颜色。这就是我所做的:
扩展操作栏并更改其属性
<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(以浅紫色为例)。
<style name="Theme.MyApp.AppBarOverlay" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar" >
<item name="android:textColorPrimary">@color/purple_200</item>
</style>
然后在您的 AppToolbar 中添加主题。这将更新您的应用栏中的 textColor
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Theme.MyApp.AppBarOverlay">
您可以看到标题现在是“浅紫色”而不是默认的“白色”
推荐阅读
- azure - 从 Azure Block 到 CosmosDB 的 Azure 数据工厂复制速度很慢
- salesforce - Apex:使用索引符号设置属性
- multithreading - 无法连接时停止频道
- java - 如何根据孩子的身高自动设置对话框高度?
- fragment - DQL 在 documentum 中查询类型片段
- r - RMarkdown 错误:包“yaml”的编译失败
- java - 像 JPanel 这样的轻量级组件可以在没有像 JFrame 这样的重量级组件的情况下显示吗?
- c# - HSTS 实施
- mysql - 如何使用案例语句优化选择查询?
- html - Bootstrap - 如何让卡片在搜索栏和视口底部之间垂直居中?