How can i change the textcolor of my timepicker and datepicker?
Asked Answered
D

3

2

Currently I am working on one of my first applications. In this application I have a TimePicker and a DatePicker. My current Activity has a dark background. Now I want a white textcolor in my TimePicker/DatePicker.

In my layout I have defined my pickers:

<DatePicker android:id="@+id/dpDateOfValue" android:calendarViewShown="false" />
<TimePicker android:id="@+id/tpTimeOfValue" />

The solution should work on 2.3 - 4.1

Duester answered 1/9, 2012 at 12:49 Comment(0)
P
1

Use:

<style name="MyHolo" parent="android:Theme.Holo.NoActionBar">

        ...

        <item name="android:editTextColor">#000000</item>
</style>

to set TimePicker text color for API >= 11

Pastille answered 28/7, 2013 at 4:52 Comment(0)
S
1

For DatePicker I use this code:

public static void setDatePickerTextColor(DatePicker dp, int color) {
    LinearLayout l = (LinearLayout) dp.getChildAt(0);
    if (l != null) {
        l = (LinearLayout) l.getChildAt(0);
        if (l != null) {
            for (int i = 0; i < 3; i++) {
                NumberPicker np = (NumberPicker) l.getChildAt(i);
                if (np != null) {
                    setNumberPickerTextColor(np, color);
                }
            }
        }
    }
}

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("NumberPickerTextColor", e);
            } catch (IllegalAccessException e) {
                Log.w("NumberPickerTextColor", e);
            } catch (IllegalArgumentException e) {
                Log.w("NumberPickerTextColor", e);
            }
        }
    }
    return false;
}

Although, it was tested only on Lollipop.

Sinusitis answered 21/12, 2016 at 10:54 Comment(0)
P
-1

I think you can do this using Coding, try following:

DatePicker your_picker = (DatePicker) findViewById(R.id.dpDateOfValue);
EditText edittext = (EditText) your_picker.findViewById(Resources.getSystem().getIdentifier("datepicker_input", "id",  "android"));

edittext.setTextColor(Color.BLUE);
Pegues answered 1/9, 2012 at 13:25 Comment(2)
Once See ThisPegues
This solution not work for me. The edittext object is always null. Is there a mistacke in the getIdentifier function?Duester

© 2022 - 2024 — McMap. All rights reserved.