如何覆盖 TimePicker 以更改文本颜色 [英] How can I override TimePicker to change text color

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

问题描述

我的视图有一个白色背景,它必须保持这种状态.我在那个白色背景上有一个 TimePicker. android 2.3.3 一切正常,但 android 4.0.3 有一个新的 timePicker 风格.数字具有非常明亮的颜色.在白色背景上很难看到它们,而且我没有找到直接更改 textColor 的方法.我不想改变背景,因为它看起来不太好.

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天全站免登陆