Android:如何更改Datepicker小部件中的日期选择器的颜色? [英] Android: How to change the color of the dateselector in Datepicker widget?

查看:1333
本文介绍了Android:如何更改Datepicker小部件中的日期选择器的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次发布一个问题。

this is my first time posting a question.

我已经在我的应用程序中成功实现了Datepicker(仅限SDK 21及更高版本)。我也想把我的Datepicker与其余的应用程序混合。这是我的:

I've successfully implemented a Datepicker in my app (targeting only SDK 21 and above). I also want to style my Datepicker to blend with the rest of the app. This is what I have:

<style name="MyDatePickerDialogTheme" parent="Theme.AppCompat.Light.Dialog">
    <item name="android:datePickerStyle">@style/MyDatePickerStyle</item>
    <item name="android:colorAccent">@color/primDark</item>
</style>

<style name="MyDatePickerStyle" parent="@android:style/Widget.Material.Light.DatePicker">
    <item name="android:headerBackground">@color/prim</item>
    <item name="android:calendarTextColor">@color/primDark</item>
    <item name="android:dayOfWeekBackground">@color/primDark</item>
    <item name="android:yearListSelectorColor">@color/accent</item>
    <item name="android:datePickerMode">calendar</item>
</style>

我无法找到属性来更改日历中的日选择器的颜色。未列出此处列出的属性。然而,我能够改变年选择器的颜色(见屏幕截图的右侧)与属性yearListSelectorColor。如何在左侧为相应的选择器和选定的文本颜色着色?

I can't find the attribute to change the color of the day selector in the calendar. No attribute listed here does that. However I was able to change the color of the year selector (see right side of the screenshot) with the attribute "yearListSelectorColor". How can I color the corresponding selector and selected text color on the left side?

为了澄清,这是我的Datepicker看起来像:屏幕截图

To clarify, this is what my Datepicker looks like: Screenshots

所以如果有人知道如何摆脱那个标准的蓝绿色,请告诉我。

So if someone knows how to get rid of that standard teal color, please tell me.

谢谢!

推荐答案

认为我得到了。

我拼命地在MyDatePickerStyle中找到一个属性。当我重新考虑整个继承层次结构时,解决方案出现在我的脑海里。我只需要添加colorAccent到MyDatePickerDialogTheme。

I tried desperately to find an attribute in MyDatePickerStyle. The solution came to my mind when I rethought the whole inheritance hierarchy. I just had to add the colorAccent to the MyDatePickerDialogTheme.

<style name="MyDatePickerDialogTheme" parent="Theme.AppCompat.Light.Dialog">
    <!-- this is new -->
    <item name="colorAccent">@color/accent</item>

    <item name="android:datePickerStyle">@style/MyDatePickerStyle</item>
    <item name="android:colorAccent">@color/primDark</item>
</style>

<style name="MyDatePickerStyle" parent="@android:style/Widget.Material.Light.DatePicker">
    <item name="android:headerBackground">@color/prim</item>
    <item name="android:calendarTextColor">@color/primDark</item>
    <item name="android:dayOfWeekBackground">@color/primDark</item>
    <item name="android:yearListSelectorColor">@color/accent</item>
    <item name="android:datePickerMode">calendar</item>
    <item name="android:minDate">01/01/2000</item>
</style>

不知何故,我认为每个主题都会自动从AppTheme中获取原色。

Somehow I thought every theme gets the primary colors from the AppTheme automatically.

希望这将有助于未来的人。

So hopefully this will help someone in the future.

这篇关于Android:如何更改Datepicker小部件中的日期选择器的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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