![](/img/trans.png)
[英]How to change color of the clock face and clock hand of time picker in Android
[英]How to Change Time Picker Font Color in Android?
嗨,我想更改我的时间选择器的字体颜色。 我在Stackoverflow本身中搜索了其他一些答案。 但我无法为此提供帮助。
我的目标API是19。这是我尝试过的事情的列表。
<!-- language: lang-xml --> <style name="MyTimePicker" parent="@android:style/Widget.Holo.DatePicker"> <item name="android:textColor">@color/main_font</item> </style>
我也尝试将其添加到values文件夹中。 但是我得到以下错误。
@android:style / Widget.Holo.DatePicker需要API级别11(当前最小值为8)
我在TimePicker中添加了样式,例如
<TimePicker
android:id="@+id/alarm_timePicker"
style="@style/MyTimePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
没有改变。
2。 我尝试在我的活动中从Stackoverflow添加一些代码。 以下是代码。
public static boolean setNumberPickerTextColor(TimePicker numberPicker) {
final int count = numberPicker.getChildCount();
int color = R.color.main_font;
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;
}
当我尝试调试它时,将内容视图设置为时出现错误
尝试在空对象引用上调用虚拟方法'void android.widget.NumberPicker.setOnValueChangedListener(android.widget.NumberPicker $ OnValueChangeListener)'
我犯了同样的错误。 我想您自己找到了答案,但是对于其他人:尝试将父样式从@android:style/Widget.Holo.DatePicker
更改为@android:style/Widget.Holo.TimePicker
。
@android:style/Widget.Material.Light.DatePicker
相同技巧,将其更改为@android:style/Widget.Material.Light.TimePicker
文本颜色是主题的textColorPrimary和textColorSecondary值。 因此,您可以创建如下样式:
<style name="myTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:textColorPrimary">#e90d8a</item>
<item name="android:textColorSecondary">@color/white_primary_text</item>
// The rest of your customization.
</style>
然后在您的活动中使用setTheme方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.