在深入研究 AOSP 主题和样式 xml 文件并进行大量谷歌搜索后,我取得了一些进展。我现在可以设计大多数(!)东西的样式。
所以这只是部分答案,还没有完全实现。但这是我所取得的进展:
您可以看到,我现在可以对标题、未(!)选择的时间部分(在本例中为分钟)、圆圈、该圆圈中的数字和“手”(或选择器)进行主题设置。哦,按钮也有样式。
让我解释一下我是如何让事情正常工作的,首先:重要的是你不能直接从应用程序的主题或(警报)对话框主题/样式覆盖事情。可以这么说,你必须从一个到下一个。
Example:
AndroidManifest.xml:为应用程序和/或活动设置自定义主题
<activity>
android:theme="@style/Theme.MyTheme"
</activity>
值-v21/styles.xml:(您的自定义主题所在的位置):设置 timePickerDialogTheme
<style name="Theme.MyTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:timePickerDialogTheme">@style/TimePickerDialogTheme</item>
</style>
然后在下面,定义 timePickerDialogTheme 并设置 timePickerStyle:
<style name="TimePickerDialogTheme" parent="@style/Theme.AppCompat.Light.Dialog">
<item name="colorAccent">#ff2d6073</item> <!-- colorAccent here seems to work just fine? -->
<item name="android:timePickerStyle">@style/TimePickerDialogStyle</item>
</style>
现在您可以在这里定义大部分样式..
<style name="TimePickerDialogStyle" parent="@android:style/Widget.Material.Light.TimePicker">
<item name="colorAccent">#ff2d6073</item> <!-- colorAccent here seems to work just fine? -->
<item name="android:timePickerMode">clock</item>
<item name="android:headerBackground">#ff2d6073</item>
<item name="android:headerTimeTextAppearance">@style/TextAppearance.TimePickerDialogStyle.TimeLabel</item> <!-- TimePicker Time *TextAppearance* -->
<item name="android:numbersTextColor">#ff000000</item>
<item name="android:numbersSelectorColor">#ff2d6073</item>
<item name="android:numbersBackgroundColor">#ffdddddd</item>
</style>
上面的重要一行是:
<item name="android:headerTimeTextAppearance">@style/TextAppearance.TimePickerDialogStyle.TimeLabel</item>
因为如果你想在标题中设置文本(实际上是时间)的样式,你需要定义 headerTimeTextAppearance:
<style name="TextAppearance.TimePickerDialogStyle.TimeLabel" parent="@android:style/TextAppearance.Material">
<item name="android:textSize">60sp</item> <!-- from -->
<item name="android:textColor">#ffD0D102</item>
</style>
现在,如果你看一下AOSP styles.xml 中的 Widget.Material.TimePicker https://android.googlesource.com/platform/frameworks/base/+/lollipop-release/core/res/res/values/styles_material.xml(ctrl-f 'timepicker' 直到找到它)您会注意到您应该能够修改的许多其他属性:
headerTimeTextAppearance
headerAmPmTextAppearance
headerSelectedTextColor
headerBackground
numbersTextColor
numbersBackgroundColor
amPmTextColor
amPmBackgroundColor
amPmSelectedBackgroundColor
numbersSelectorColor
其中大部分都可以工作(只要你为每个都添加“android:”),但我无法让“headerSelectedTextColor”工作。我收到一个编译错误,提示“无法匹配属性 bla bla”。另外,如果您查看上面的示例,我会硬编码“headerTimeTextAppearance”属性的 textSize,因为“@dimen/timepicker_ampm_label_size”值会引发错误。
简而言之:上面列出了大部分内容以及如何让它们发挥作用。但并非一切都清楚。所以我仍然会看到完整的文档/指南:)