【问题标题】:Android Datepicker Single Cell ColorAndroid Datepicker 单格颜色
【发布时间】:2018-09-11 04:27:52
【问题描述】:

您好,我希望能够在一个月中选择几个日期并更改其颜色。假设在我的应用程序中,我希望 9 月 3 日、4 日、8 日的日期为红色,以便用户能够知道在这些特定日期已经有提交。这可能吗,如果可以,怎么办?提前致谢!

编辑。我试过搜索论坛,搜索其他地方,但无法得到答案。

为了清楚起见,我不只是想改变颜色主题,我想改变特定日期的颜色。假设用户在 9 月 8 日提交了一些内容。我希望我的应用程序日期选择器通过更改日期选择器窗口中数字 8 的颜色来显示这一点。

【问题讨论】:

    标签: android android-layout android-studio datepicker


    【解决方案1】:

    查看library 以显示不同颜色主题的日期:

    添加到你的styles.xml

    <style name="MyDatePickerDialogTheme" parent="android:Theme.Material.Light.Dialog">
        <item name="android:datePickerStyle">@style/MyDatePickerStyle</item>
        <item name="android:colorAccent">@color/beautiful_color</item>
    </style>
    
    <style name="MyDatePickerStyle" parent="@android:style/Widget.Material.Light.DatePicker">
        <item name="android:headerBackground">@color/beautiful_color</item>
        <item name="android:datePickerMode">calendar</item>
    </style>
    

    另外,如果要更改日期选择器的整个主题,请使用以下依赖项

    dependencies {
        compile 'com.wdullaer:materialdatetimepicker:3.6.3'
    }
    

    您可以使用 app:mcv_dateTextAppearance(或 Java setter)来执行此操作。我没有完整的解释,但现在,您可以复制默认实现并根据需要进行修改。本质上,您需要提供一个 android:textColor ,它是一个带有您想要的颜色的颜色状态列表。

    添加样式:

    <style name="TextAppearance.MyCustomDay" parent="android:TextAppearance.DeviceDefault.Small">
        <item name="android:textSize">12sp</item>
        <item name="android:textColor">@color/my_custom_day_color</item>
    </style>
    

    并创建 color/my_custom_day_color.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android"
        android:enterFadeDuration="@android:integer/config_shortAnimTime"
        android:exitFadeDuration="@android:integer/config_shortAnimTime">
    
        <item android:state_checked="true" android:color="SELECTION_COLOR" />
        <item android:state_pressed="true" android:color="SELECTION_COLOR" />
        <item android:state_enabled="false"  android:color="#808080" />
        <item android:color="@android:color/black" />
    </selector>
    

    然后设置 app:mcv_dateTextAppearance="@style/TextAppearance.MyCustomDay"

    【讨论】:

    • 嗨@Paramjeet ...下次每当您给出答案时,请在其中添加一些代码。**参考仅在 SO 中回答** 不允许 因为链接将来可能会过期或完成,所以下次请在链接中给出一些描述。享受编码并继续帮助他人:)
    • 正如我在我的问题中所写,这是针对 android studio... 不是 html... 我不知道您给我的链接
    • 请检查更新的代码参考@RavindraKushwaha
    猜你喜欢
    • 1970-01-01
    • 2012-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多