更改DatePicker文本颜色 [英] Change DatePicker Text Color

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

问题描述

我想更改DatePicker的文本颜色.

我尝试了一些在这里找到的建议,但对我没有任何帮助. 文字颜色和所选背景保持不变.

I have tried couple of suggestions found here but nothing has worked for me. The text color, and the selected background stays the same.

顶部标题背景确实发生了变化.

The top header background did changed.

<style name="MyThemeDesign" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/btnColor</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="android:datePickerStyle">@style/MyDatePickerStyle</item>
</style>

<style name="MyDatePickerStyle" parent="@android:style/Widget.Material.Light.DatePicker">
        <item name="android:headerBackground">@color/orange</item>
        <item name="android:text">@color/white</item>
        <item name="android:calendarTextColor">@color/white</item>
        <item name="android:dayOfWeekBackground">@color/white</item>
        <item name="android:selectedWeekBackgroundColor">@color/colorRed</item>
        <item name="android:yearListSelectorColor">@color/colorRed</item>
        <item name="android:colorPrimary">@color/white</item>
        <item name="android:colorPrimaryDark">@color/white</item>
        <item name="android:colorBackgroundCacheHint">@color/colorRed</item>
        <item name="colorAccent">@color/white</item>
        <item name="android:textColorPrimary">@color/white</item>
        <item name="android:datePickerMode">calendar</item>
        <item name="android:minDate">01/01/2017</item>
</style>

推荐答案

styles.xml中:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
  ...
  <item name="android:datePickerStyle">@style/MyDatePickerStyle</item>
</style>

<style name="MyDatePickerStyle" parent="@android:style/Widget.DeviceDefault.DatePicker">
  <item name="android:headerBackground">@color/red</item>
  <item name="android:headerMonthTextAppearance">@style/MyDatePickerTextAppearance</item>
</style>

<style name="MyDatePickerTextAppearance" parent="TextAppearance.AppCompat.Body1">
  <item name="android:textColor">@drawable/my_color_state_list</item>
</style>

drawable/my_color_state_list.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <!-- Month color -->
  <item android:color="@color/yellow" android:state_selected="true"/>
  <!-- Year color -->
  <item android:color="@color/purple" />
</selector>

如果您还想控制选定的日期颜色,则将此主题添加到style.xml:

If you also want to control the selected date color, then add this theme to style.xml:

<style name="MyDatePickerTheme" parent="AppTheme">
  <item name="colorAccent">@color/blue</item>
</style>

在布局中:

<DatePicker
    android:theme="@style/MyDatePickerTheme"
    .../>

结果:

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

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