Armadillo Armadillo - 4 months ago 79
Android Question

Android divider color DatePicker dialog

I'm trying to change color of the blue dividers for a DatePicker in a dialog. This is just a normal DialogFragment with a DatePicker and a ButtonBar.

Does anyone know to change these dividers, or if it's even possible without replacing the entire DatePicker with a custom one?

Screenshot DatePicker

Mini rant

Now I've seen too many answers suggesting the following code:

<style name="datePickerTheme" parent="@android:style/Widget.DeviceDefault.DatePicker">
<item name="android:divider">**your @drawable/ or @color/ here**</item>

Which simply does not work. Have you guys tried this before suggesting this code? It should work perfectly, but it does not seem to work with the DatePicker.


The following approach worked for me.This sets divider colours for all fields (also for am/pm)

 private void applyStyLing(TimePickerDialog timePickerDialog){
    Resources system = Resources.getSystem();
    int hourNumberPickerId = system.getIdentifier("hour", "id", "android");
    int minuteNumberPickerId = system.getIdentifier("minute", "id", "android");
    int ampmNumberPickerId = system.getIdentifier("amPm", "id", "android");

    NumberPicker hourNumberPicker = (NumberPicker) timePickerDialog.findViewById(hourNumberPickerId);
    NumberPicker minuteNumberPicker = (NumberPicker) timePickerDialog.findViewById(minuteNumberPickerId);
    NumberPicker ampmNumberPicker = (NumberPicker) timePickerDialog.findViewById(ampmNumberPickerId);


private void setNumberPickerDividerColour(NumberPicker number_picker){
    final int count = number_picker.getChildCount();

    for(int i = 0; i < count; i++){

            Field dividerField = number_picker.getClass().getDeclaredField("mSelectionDivider");
                ColorDrawable colorDrawable = new ColorDrawable(mContext.getResources().getColor(R.color

        catch(NoSuchFieldException e){
            Log.w("setNumberPickerTxtClr", e);
        catch(IllegalAccessException e){
            Log.w("setNumberPickerTxtClr", e);
        catch(IllegalArgumentException e){
            Log.w("setNumberPickerTxtClr", e);