【问题标题】:DatePicker Android - How to change the color of daysDatePicker Android - 如何更改日期的颜色
【发布时间】:2016-03-12 04:53:35
【问题描述】:

我有这个布局:

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <DatePicker
        style="@style/MyDatePickerStyle"
        android:id="@+id/datePicker"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dip"
        android:layout_marginRight="5dip"
        android:calendarViewShown="false"
        android:calendarTextColor="@color/Black"
        android:headerDayOfMonthTextAppearance="@color/accent_color"
        android:background="@color/gray_light_date"
        android:headerBackground="@color/app_bar_color"
        android:dayOfWeekBackground="@color/app_bar_color"
        android:dayOfWeekTextAppearance="@color/Black"
        />
</LinearLayout>

布局使用的样式:

<style name="MyDatePickerStyle" parent="@android:style/Widget.Holo.DatePicker">
    <item name="android:headerBackground">@color/ColorPrimary</item>
    <item name="android:calendarTextColor">@color/ColorPrimaryDark</item>
    <item name="android:dayOfWeekBackground">@color/ColorPrimaryDark</item>
    <item name="android:yearListSelectorColor">@color/accent_color</item>
    <item name="android:datePickerMode">calendar</item>
</style>

您可以在下面看到此布局生成的屏幕:

我想更改那些月份的文本颜色。

它目前是白色的,我想改变它而不是背景。

我在google上搜索,尝试了很多不同的属性和样式,但都没有成功。

你能帮帮我吗?

谢谢。

【问题讨论】:

标签: android datepicker


【解决方案1】:

您必须在 Android 原生中更改 datePicker 小部件的字体颜色吗?
然后你必须实现下面对你有帮助的代码。

DatePicker picker;
ViewGroup childpicker;

childpicker = (ViewGroup) findViewById(Resources.getSystem().getIdentifier("month" /*rest is: day, year*/,    "id", "android"));
EditText textview = (EditText) picker.findViewById(Resources.getSystem().getIdentifier("timepicker_input", "id",  "android"));
textview.setTextColor(Color.GREEN);

风格上的 OR

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.SelectDate" parent=" <at> android:style/Theme.Holo.NoActionBar">
    <item name="android:editTextStyle"> <at> style/Widget.EditText.Black</item>
</style>

<style name="Widget.EditText.Black" parent=" <at> android:style/Widget.EditText">
    <item name="android:textColor"> <at> color/black</item>
</style>

【讨论】:

    猜你喜欢
    • 2020-02-20
    • 2023-03-19
    • 1970-01-01
    • 2015-08-11
    • 2010-10-22
    • 1970-01-01
    • 2021-11-27
    • 2021-08-27
    • 1970-01-01
    相关资源
    最近更新 更多