How can I override TimePicker to change text color

随声附和 提交于 2019-11-28 02:26:34

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" />

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;

}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!