REJ*_*EJH 9 android android-timepicker android-styles
我正在尝试为sdk 21+(Lollipop)设置TimePickerDialog的样式.到目前为止,我已经想出如何更改XML中的默认colorscheme:
<style name="TimePickerTheme" parent="@style/Theme.AppCompat.Light.Dialog">
<item name="colorPrimary">#ff2d6073</item> <!-- no effect -->
<item name="colorPrimaryDark">#ff2d6073</item> <!-- no effect -->
<item name="colorAccent">#ff2d6073</item>
<item name="android:textColor">#ffD0D102</item>
<item name="android:textColorPrimary">#ffD0D102</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这有效,但我正在寻找我可以更改的所有属性的指南或文档.
但是,例如,我需要更改对话框"标题"中的大文本(显示当前所选时间)的属性?
是否有一些文档列出了您可以更改的所有内容?
REJ*_*EJH 23
在深入研究AOSP主题和样式xml文件以及大量谷歌搜索后,我取得了一些进展.我现在能够设置大多数(!)的东西.
所以这是一个部分答案,而不是所有的方式.但这是我有多远:
你可以看到我现在能够设置标题,un(!)选择的时间部分(在这种情况下是分钟),圆圈,圆圈中的数字和'手'(或选择器).哦,按钮也有样式.
让我解释一下我是如何让事情起作用的,首先:重要的是你不能直接从你的应用主题或(警报)对话框主题/风格中覆盖事物.你必须从一个到另一个,可以这么说.
例:
AndroidManifest.xml:为应用和/或活动设置自定义主题
<activity>
android:theme="@style/Theme.MyTheme"
</activity>
Run Code Online (Sandbox Code Playgroud)
values-v21/styles.xml :(您的自定义主题所在的位置):设置timePickerDialogTheme
<style name="Theme.MyTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:timePickerDialogTheme">@style/TimePickerDialogTheme</item>
</style>
Run Code Online (Sandbox Code Playgroud)
然后在下面,定义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>
Run Code Online (Sandbox Code Playgroud)
现在你可以在这里定义大部分样式..
<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>
Run Code Online (Sandbox Code Playgroud)
以上重点是:
<item name="android:headerTimeTextAppearance">@style/TextAppearance.TimePickerDialogStyle.TimeLabel</item>
Run Code Online (Sandbox Code Playgroud)
因为如果要在标题中设置文本样式(实际上是时间,实际上),则需要定义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>
Run Code Online (Sandbox Code Playgroud)
现在,如果您看一下AOSP styles.xml中的Widget.Material.TimePicker(ctrl -f'timepicker',直到找到它),您会发现一些您应该能够修改的其他属性:
headerTimeTextAppearance headerAmPmTextAppearance headerSelectedTextColor headerBackground numbersTextColor numbersBackgroundColor amPmTextColor amPmBackgroundColor amPmSelectedBackgroundColor numbersSelectorColor
大多数这些工作(只要你为每个人前置'android:')但我无法让'headerSelectedTextColor'工作.我得到一个编译错误,说"无法匹配属性bla bla".另外,如果你看一下上面的例子,我将textSize硬编码为'headerTimeTextAppearance'属性,因为'@ dimen/timepicker_ampm_label_size'值会引发错误.
简而言之:上面列出了大部分内容以及如何使它们正常工作.但并非一切都很清楚.所以我仍然会看到完整的文档/指南:)
Android TimePicker 材质样式与下方自定义颜色,您可以查看http://www.zoftino.com/android-timepicker-example了解 TimePicker 的用法和样式。
<style name="MyAppThemeFour" parent="Theme.AppCompat.Light">
<item name="android:timePickerDialogTheme">@style/MyTimePickerDialogStyle</item>
</style>
<style name="MyTimePickerDialogStyle" parent="@style/ThemeOverlay.AppCompat.Dialog.Alert">
<item name="showTitle">false</item>
<item name="colorControlActivated">#ffd600</item>
<item name="colorAccent">#b71c1c</item>
<item name="android:textColorPrimary">#43a047</item>
<item name="android:textColorSecondary">#f44336</item>
</style>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6893 次 |
| 最近记录: |