0

My view has a white background, and it has to stay that way. I have a TimePicker on that white background.Everything is woking fine with android 2.3.3 but android 4.0.3 has a new timePicker style. The numbers have a very bright color. It is very hard to see them on the white background, and I didn't find a direct way to change the textColor. I don't want to change the background because it would look not so good.

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

Sincerly, Wolfen

Wolfen
  • 380
  • 1
  • 5
  • 18

2 Answers2

0

Take a look at the android source for styles.xml

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

You then set a style on your activity/timepicker 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 (3.0 and above only)

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

Then your xml would be:

<TimePicker
 style="@style/MyHoloTimePicker"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent" />
Blundell
  • 75,855
  • 30
  • 208
  • 233
  • @Wolfen yes, why would you think you couldn't? – Blundell Jun 10 '12 at 14:44
  • 1
    Okay I added this to my styles.xml: error: Error retrieving parent for item: No resource found that matches the given name 'Widget' – Wolfen Jun 10 '12 at 15:19
  • @Wolfen all you've done is copy and paste out of the source, thats not what I said do. My answer shows you inherit from the source and override what you need – Blundell Jun 10 '12 at 15:42
  • inherit what? You should post actual working cod that should work. i tried your code snippet myself and tried to locate the timePicker class on styles/Widget but there is no resource for it. – Jono Aug 12 '13 at 15:37
  • it is there https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/values/styles.xml – Blundell Aug 12 '13 at 16:17
  • 2
    this answer is distracting ... -1 – Ahmed Adel Ismail Jun 01 '14 at 11:04
0

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;

}

Hari Ram
  • 3,098
  • 5
  • 23
  • 30