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

biegleux
  • 13,179
  • 11
  • 45
  • 52
user1640506
  • 21
  • 1
  • 3

3 Answers3

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

i.shadrin
  • 5,038
  • 2
  • 21
  • 13
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.

DeniSHow
  • 1,394
  • 1
  • 18
  • 30
-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);
Chintan Raghwani
  • 3,370
  • 4
  • 22
  • 33