3

I am tying to change the divider color of the DatePicker Dialog.

I already checked all duplicate questions but i didn't get anything which is working.

I want to use orange color instead of this blue color of this divider.

Right now my datepicker looks like this and i also want to remove this background of whole date picker.

I used this code for datepicker dialog

final Calendar calendarDate = Calendar.getInstance();

DatePickerDialog.OnDateSetListener dateSetListener = new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear,
                            int dayOfMonth) {
            calendarDate.set(Calendar.YEAR, year);
            calendarDate.set(Calendar.MONTH, monthOfYear);
            calendarDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
        }
};
DatePickerDialog datePickerDialog = new DatePickerDialog(mContext,
        dateSetListener, calendarDate.get(Calendar.YEAR), calendarDate
                .get(Calendar.MONTH), calendarDate
                .get(Calendar.DAY_OF_MONTH));
datePickerDialog.getDatePicker().setCalendarViewShown(false);
datePickerDialog.show();

Screeshot :

enter image description here

sam_k
  • 5,983
  • 14
  • 76
  • 110

1 Answers1

0

Use Custom Style to change the divider color/theme from your drawable image as below:

 <?xml version="1.0" encoding="utf-8"?>
   <resources xmlns:android="http://schemas.android.com/apk/res/android">
     <style name="YourTheme" parent="@android:style/Theme">
        <item name="android:divider">@drawable/dialog_divider_color</item>
     </style>
   </resources>

and update the AndroidManifest.xml file with the android:theme="YourTheme" for the <activity/>

Avadhani Y
  • 7,566
  • 19
  • 63
  • 90
  • For this i have to create image looks like divider? or i can use orange color directly? – sam_k Jun 26 '13 at 05:58
  • You can use either image/color using above code. For image, Place the image in `drawable` folder and place `@drawable/your_image_name`. For Color, place `@color/your_color` in the above code. – Avadhani Y Jun 26 '13 at 06:01
  • 1
    I have to use Compulsary `parent="@android:style/Theme"` ? because in my case its `parent="@android:style/Theme.Holo.NoActionBar"`as i need this type of theme – sam_k Jun 26 '13 at 06:04
  • Thanks for your reply.. But its not working. I am checking in android 4.2 google nexus 4 phone – sam_k Jun 26 '13 at 06:40
  • @Sam_k In-detail analysis here: [Android: how to change the color of the datepicker divider?](http://stackoverflow.com/questions/20148671/android-how-to-change-the-color-of-the-datepicker-divider). – user3264740 Feb 14 '14 at 21:43