對於我的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;
}
雖然,它只是在棒棒糖測試。
[曾見此](http://grokbase.com/t/gg/android-developers/1287p4zckr/changing-text-color-font-for-datepicker-widget) –
此解決方案對我無效。 edittext對象始終爲空。 getIdentifier函數中是否有錯誤? – user1640506