更改TimePickerDialog样式 [英] Changing TimePickerDialog Styles

查看:584
本文介绍了更改TimePickerDialog样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更改TimePicker的样式,但无法更改钟面和标题背景的颜色.这是我的XML样式代码-

I want to change the style of my TimePicker but I can't get to change the color of the clock face and the header background. Here's my XML style code -

    <style name="DateTimeDialog" parent="Theme.AppCompat.Dialog">
        <item name="android:colorBackground">@color/colorWhite</item>
        <item name="android:textColorPrimary">#000000</item>
        <item name="android:headerBackground">#000000</item>
        <item name="android:textColorSecondary">#000000</item>
        <item name="android:button">@color/colorWhite</item>
        <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="android:colorAccent">@color/colorSecondary</item>
        <item name="android:textColor">@color/colorSecondaryDark</item>
    </style>

原色是海军蓝色,而强调色/次要颜色是浅蓝色(以防万一,您希望将其描绘出来).这是当前的样子-

The primary color is navy blue, and the accent/secondary color is light blue (just in case you want to picture it). Here is how it looks currently -

当前样式

我希望能够更改灰色背景.

I want to be able to change that Grey background.

注意:'android:background'属性在这里不起作用.它仅更改标题中显示的时间中:"后面的微小区域的颜色.任何帮助/资源表示赞赏.谢谢!

NOTE: The 'android:background' attribute doesn't work here. It only changes the color of a tiny area behind the ":" in the time displayed in the header. Any help/resources appreciated. Thanks!

推荐答案

尝试尝试

    <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> 

    <style name="MyTimePickerWidgetStyle" parent="@android:style/Widget.Material.TimePicker">
    <item name="android:headerBackground">#ffe082</item>
    <item name="android:numbersTextColor">#b71c1c</item>
    <item name="android:numbersInnerTextColor">#f44336</item>
    <item name="android:numbersSelectorColor">#33691e</item>
    <item name="android:numbersBackgroundColor">#ef9a9a</item>
    <item name="android:amPmTextColor">#9c27b0</item>
</style>

将其应用于时间选择器,例如:

Apply it to the timepicker like :

<TimePicker
android:id="@+id/timePicker"
android:theme="@style/MyTimePickerWidgetStyle"
style="@style/MyTimePickerWidgetStyle"
. . . />

这篇关于更改TimePickerDialog样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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