2

目前我正在开发我的第一个应用程序。在这个应用程序中,我有一个TimePicker和一个DatePicker. 我的电流Activity有一个黑暗的背景。现在我想要TimePicker/中的白色文本颜色DatePicker

在我的布局中,我定义了我的选择器:

<DatePicker android:id="@+id/dpDateOfValue" android:calendarViewShown="false" />
<TimePicker android:id="@+id/tpTimeOfValue" />

该解决方案应适用于 2.3 - 4.1

4

3 回答 3

1

利用:

<style name="MyHolo" parent="android:Theme.Holo.NoActionBar">

        ...

        <item name="android:editTextColor">#000000</item>
</style>

为 API >= 11 设置 TimePicker 文本颜色

于 2013-07-28T04:52:19.340 回答
1

对于 DatePicker,我使用以下代码:

public static void setDatePickerTextColor(DatePicker dp, int color) {
    LinearLayout l = (LinearLayout) dp.getChildAt(0);
    if (l != null) {
        l = (LinearLayout) l.getChildAt(0);
        if (l != null) {
            for (int i = 0; i < 3; i++) {
                NumberPicker np = (NumberPicker) l.getChildAt(i);
                if (np != null) {
                    setNumberPickerTextColor(np, color);
                }
            }
        }
    }
}

public static boolean setNumberPickerTextColor(NumberPicker numberPicker, int color) {
    final int count = numberPicker.getChildCount();
    for (int i = 0; i < count; i++) {
        View child = numberPicker.getChildAt(i);
        if (child instanceof EditText) {
            try {
                Field selectorWheelPaintField = numberPicker.getClass()
                        .getDeclaredField("mSelectorWheelPaint");
                selectorWheelPaintField.setAccessible(true);
                ((Paint) selectorWheelPaintField.get(numberPicker)).setColor(color);
                ((EditText) child).setTextColor(color);
                numberPicker.invalidate();
                return true;
            } catch (NoSuchFieldException e) {
                Log.w("NumberPickerTextColor", e);
            } catch (IllegalAccessException e) {
                Log.w("NumberPickerTextColor", e);
            } catch (IllegalArgumentException e) {
                Log.w("NumberPickerTextColor", e);
            }
        }
    }
    return false;
}

虽然,它仅在 Lollipop 上进行了测试。

于 2016-12-21T10:54:44.770 回答
-1

我认为您可以使用 Coding 来做到这一点,请尝试以下操作:

DatePicker your_picker = (DatePicker) findViewById(R.id.dpDateOfValue);
EditText edittext = (EditText) your_picker.findViewById(Resources.getSystem().getIdentifier("datepicker_input", "id",  "android"));

edittext.setTextColor(Color.BLUE);
于 2012-09-01T13:25:23.190 回答