android - 如何将样式应用于自定义首选项 TimePicker?
问题描述
我想为我的 TimePicker 首选项使用自定义样式更改文本颜色,但我似乎无法覆盖默认主题。
这是我的主题资源文件:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Posture" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/purple_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<item name="android:colorBackground">@color/purple_500</item>
<item name="android:textColor">@color/white</item>
<item name="android:textColorSecondary">@color/grey_dark</item>
</style>
我正在使用 PreferenceDialogFragmentCompat 和 DialogPreference 创建自定义 TimePicker。
这是我在对话框中膨胀的布局:
<?xml version="1.0" encoding="utf-8"?>
<TimePicker
style="@style/TimePickerStyle"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/timePicker"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
我尝试创建一种样式,但是当我在时间选择器中使用它时,它不会被应用。
<style name="TimePickerStyle">
<item name="android:textColor">@color/blue</item>
<item name="android:textColorPrimary">@color/blue</item>
<item name="android:textColorSecondary">@color/blue</item>
</style>
我该如何解决这个问题?
解决方案
试试看:
<?xml version="1.0" encoding="utf-8"?>
<TimePicker
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/timePicker"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/TimePickerStyle"/>
和风格:
<style name="TimePickerStyle">
<item name="android:numbersTextColor">@color/blue</item>
<item name="android:numbersSelectorColor">@color/blue</item>
<item name="android:numbersBackgroundColor">@color/blue</item>
</style>
推荐阅读
- oracle12c - osb 12c 中的存储过程调用
- javascript - javascript & css:如何在覆盖 div 上动态创建 SVG 并定义大小
- python - 将ÿ字符转换为单字节0xFF python
- c# - 使用 Azure gremlin 查询验证文档是否存在
- c++ - 程序托管 - 任一方向的隧道/NAT IPv4/IPv6
- jquery - 如何禁用基于会话变量的按钮悬停?
- c - 使用 ftok() 创建密钥以及如何使用密钥?
- django - user.has_perm 是假的,即使我可以在管理页面和 user.user_permissions 中看到它
- javascript - 如何使用 JavaScript 读取 2 个 MongoDB 集合?
- swift - 在 Swift 4 中,如何正确隐藏 tabBar?