How to override TimePicker to change text color

My view has a white background, and it should remain so. I have a TimePicker on this white background. Everything does fine with Android 2.3.3, but Android 4.0.3 has a new timePicker style. The numbers have a very bright color. They are very difficult to see on a white background, and I did not find a direct way to change textColor. I do not want to change the background, because it does not look very good.

Is there any way to override this and set the color of the numbers to black?

Sincerly, Wolfen

0
android override overriding colors timepicker android-4.0-ice-cream-sandwich
source share
2 answers

Take a look at android source for styles.xml

https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/styles.xml

Then you set your activity / time style, it looks like you could do something like this:

<style name="MyTimePicker" parent="@android:style/Widget.TimePicker"> <item name="android:textColor">#000000</item> </style> 

or maybe (only 3.0 and above)

 <style name="MyHoloTimePicker" parent="@android:style/Widget.Holo.TimePicker"> <item name="android:textColor">#000000</item> </style> 

Then your xml will be:

 <TimePicker style="@style/MyHoloTimePicker" android:layout_width="fill_parent" android:layout_height="fill_parent" /> 
0
source share

use this function

 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("setNumberPickerTextColor", e); } catch (IllegalAccessException e) { Log.w("setNumberPickerTextColor", e); } catch (IllegalArgumentException e) { Log.w("setNumberPickerTextColor", e); } } } return false; 

}

0
source share

All Articles