Android TimePicker labels text color

37 Views Asked by At

I want to change the text color of the hour, minute and am/pm label in TimePicker (see green box).

Setting the style does only change the text color of the time picker itself:

 <style name="MyTimePickerStyle" parent="@android:style/Widget.Material.TimePicker">
        <item name="android:textColor">@color/red</item>
        <item name="android:textColorPrimary">@color/red</item>
    </style>  

If I do it programmatically, the text color is persistent, but I need some kind of selector, so that the not selected labels are semi-transparent and the other way around:

setTimePickerTextColor(timePicker, "hours");
    setTimePickerTextColor(timePicker, "separator");
    setTimePickerTextColor(timePicker, "minutes");
    setTimePickerTextColor(timePicker, "am_label");
    setTimePickerTextColor(timePicker, "pm_label");

private void setTimePickerTextColor(TimePicker timePicker, String viewId) {
    final int id = Resources.getSystem().getIdentifier(viewId, "id", "android");
    final TextView textView = timePicker.findViewById(id);
    if (textView != null) {
        textView.setTextColor(AttributeUtils.getAttributeValue(this, R.attr.customTextColor));
    }
}

How can I achieve this?

enter image description here

0

There are 0 best solutions below