目前我正在处理我的第一个应用程序。在此应用程序中,我有一个TimePicker
和一个DatePicker
。我当前的Activity
背景较暗。现在我想要TimePicker
/ DatePicker
中的白色文字颜色。
在我的布局中,我定义了我的选择器:
<DatePicker android:id="@+id/dpDateOfValue" android:calendarViewShown="false" />
<TimePicker android:id="@+id/tpTimeOfValue" />
解决方案应该适用于2.3 - 4.1
答案 0 :(得分:1)
使用:
<style name="MyHolo" parent="android:Theme.Holo.NoActionBar">
...
<item name="android:editTextColor">#000000</item>
</style>
为API&gt; = 11
设置TimePicker文本颜色答案 1 :(得分: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上进行了测试。
答案 2 :(得分:-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);