如何覆盖TimePicker以更改文本颜色

问题描述 投票:0回答:2

我的观点有白色背景,它必须保持这种状态。我在那个白色的背景上有一个TimePicker。用android 2.3.3一切都很好,但android 4.0.3有一个新的timePicker风格。数字颜色非常鲜艳。很难在白色背景上看到它们,我没有找到更改textColor的直接方法。我不想改变背景,因为它看起来不太好。

有没有办法覆盖它并将数字的颜色设置为黑色?

真诚的,沃尔芬

android colors override android-4.0-ice-cream-sandwich timepicker
2个回答
0
投票

看一下styles.xml的android源码

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

然后,您在活动/时间戳上设置一个样式,看起来您可以执行以下操作:

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

或者(仅3.0以上)

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

然后你的xml将是:

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

0
投票

使用此功能

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;

}

© www.soinside.com 2019 - 2024. All rights reserved.