我如何可以覆盖TimePicker改变文字颜色 [英] How can I override TimePicker to change text color

查看:512
本文介绍了我如何可以覆盖TimePicker改变文字颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的观点有一个白色背景,它具有保持这种方式。 我有白background.Everything一个TimePicker沃金是细跟的Andr​​oid 2.3.3但是Android 4.0.3有一个新的timePicker风格。该数字有一个很亮的颜色。这是很难看到他们的白色背景,而我没有找到一个直接的方式来改变文字颜色。我不想改变背景,因为它看起来不那么好。

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?

诚恳, 沃尔芬

推荐答案

使用此功能

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;

}

这篇关于我如何可以覆盖TimePicker改变文字颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆