Change Divider Color Android DatePicker Dialog
Asked Answered
R

2

2

I´m tying to change the divider color of the DatePicker Dialog.

I create the style:

<style name="dialog_custom" parent="@android:style/Widget.DatePicker">
        <item name="android:divider">@drawable/dialog_divider</item>
    </style>

And create the drawable like this

And the result is this

The divider no change color and the dialog take the content size..

Rooney answered 13/2, 2013 at 8:16 Comment(0)
R
-1

You can do this using theme. Check accepted answer on this question. i think it will helpful to you.

UPDATES

Expand res folder in your application and expand values folder. Then create themes.xml file on values folder. then replace all code in themes.xml file with below code.

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="MYTheme" parent="@android:style/Theme">

       <item name="android:divider">@drawable/dialog_divider</item>

    </style>

</resources>

Then open your AndroidManifest.xml file. and find android:theme and replcae with android:theme="@style/MYTheme"

Retinite answered 13/2, 2013 at 8:25 Comment(9)
When I do this I get this error: error: Error: No resource found that matches the given name: attr 'android:_DEFAULT_BASE_COLOR_1'.Rooney
Did you define _DEFAULT_BASE_COLOR_1 in your resources ?Retinite
Sorry but...What resources? How I can define it?Rooney
I try generate all resources with this, android-ui-utils.googlecode.com/hg/asset-studio/dist/index.html. But the default color of the dividers no change..Rooney
sorry but i get this error again..see the link dl.dropbox.com/u/30331820/ERROR.pngRooney
updated my answer with <item name="android:divider">@drawable/dialog_divider</item>Retinite
I set a style with android-ui-utils.googlecode.com like this: <style name="AppTheme" parent="android:Theme.Holo.Light"> <item name="android:actionBarStyle">@null</item> <item name="android:divider">@drawable/divider_dialog</item> <item name="android:editTextB.... </style>, with all the nine-patch drawables but this line blue not change. I create de "dialog_divider" like a nine-patch and put in the style but the line blue persist...any way to change the blue line divider in android style holo.light?Rooney
Did you find any solution? This answer is accepted but doesn't provide any…Seminar
@Kernald In-detail analysis here: Android: how to change the color of the datepicker divider?.Tibold
W
1

This is my solution to change divider colors in NumberPickers, TimePickers, DatePickers and the TimePickerDialog. For DatePickerDialog you can call DatePickerDialog.getDatePicker()

public class NumberPickerStylingUtils {

private static final Drawable PICKER_DIVIDER_DRAWABLE = //Place your drawable here

private NumberPickerStylingUtils() {}

public static void applyStyling(TimePickerDialog timePickerDialog) {
    try {
        Field field = TimePickerDialog.class.getDeclaredField("mTimePicker");
        field.setAccessible(true);
        applyStyling((TimePicker) field.get(timePickerDialog));
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}

public static void applyStyling(TimePicker timePicker) {
    try {
        Field fields[] = TimePicker.class.getDeclaredFields();
        for (Field field : fields) {
            if (field.getType().equals(NumberPicker.class)) {
                field.setAccessible(true);
                applyStyling((NumberPicker) field.get(timePicker));
            }
        }
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}

public static void applyStyling(DatePicker datePicker) {
    try {
        Field fields[] = DatePicker.class.getDeclaredFields();
        for (Field field : fields) {
            if (field.getType().equals(NumberPicker.class)) {
                field.setAccessible(true);
                applyStyling((NumberPicker) field.get(datePicker));
            }
        }
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}

public static void applyStyling(NumberPicker numberPicker) {
    try {
        Field field = NumberPicker.class.getDeclaredField("mSelectionDivider");
        field.setAccessible(true);
        field.set(numberPicker, PICKER_DIVIDER_DRAWABLE));
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}

}

Waistline answered 17/12, 2014 at 12:14 Comment(0)
R
-1

You can do this using theme. Check accepted answer on this question. i think it will helpful to you.

UPDATES

Expand res folder in your application and expand values folder. Then create themes.xml file on values folder. then replace all code in themes.xml file with below code.

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

    <style name="MYTheme" parent="@android:style/Theme">

       <item name="android:divider">@drawable/dialog_divider</item>

    </style>

</resources>

Then open your AndroidManifest.xml file. and find android:theme and replcae with android:theme="@style/MYTheme"

Retinite answered 13/2, 2013 at 8:25 Comment(9)
When I do this I get this error: error: Error: No resource found that matches the given name: attr 'android:_DEFAULT_BASE_COLOR_1'.Rooney
Did you define _DEFAULT_BASE_COLOR_1 in your resources ?Retinite
Sorry but...What resources? How I can define it?Rooney
I try generate all resources with this, android-ui-utils.googlecode.com/hg/asset-studio/dist/index.html. But the default color of the dividers no change..Rooney
sorry but i get this error again..see the link dl.dropbox.com/u/30331820/ERROR.pngRooney
updated my answer with <item name="android:divider">@drawable/dialog_divider</item>Retinite
I set a style with android-ui-utils.googlecode.com like this: <style name="AppTheme" parent="android:Theme.Holo.Light"> <item name="android:actionBarStyle">@null</item> <item name="android:divider">@drawable/divider_dialog</item> <item name="android:editTextB.... </style>, with all the nine-patch drawables but this line blue not change. I create de "dialog_divider" like a nine-patch and put in the style but the line blue persist...any way to change the blue line divider in android style holo.light?Rooney
Did you find any solution? This answer is accepted but doesn't provide any…Seminar
@Kernald In-detail analysis here: Android: how to change the color of the datepicker divider?.Tibold

© 2022 - 2024 — McMap. All rights reserved.