0

I'm using a DatePickerDialog in a DialogFragment, which works fine.

I would like to change the colors of:

  • the background of the action bar
  • the background of the buttons
  • the dividers

Here is my DialogFragment:

public class DatePickerDialogFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener
{

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState)
    {
        // init :
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH);
        int day = calendar.get(Calendar.DAY_OF_MONTH);

        DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), R.style.DatePickerDialogTest, this, year, month, day);
        datePickerDialog.getDatePicker().setBackgroundColor(0xFF500000);

        return datePickerDialog;
    }

    ...
}

And here is the style:

<style name="DatePickerDialogTest" parent="Theme.AppCompat.Dialog.Alert">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:textColorPrimary">#FF00FF00</item>
    <item name="colorAccent">#FFFF0000</item>
    <item name="android:divider">@android:color/holo_purple</item>
</style>

Every color I use displays properly, except for the backgrounds of the action bar, buttons and dividers.

Is there any way I can easily change those colors?

Thanks.

matteoh
  • 2,810
  • 2
  • 29
  • 54
  • [This](http://stackoverflow.com/q/20148671/6570665) can help you change the divider color at least. A similar approach might also help you change the button and action bar color. – Harsh Pandey Jul 13 '16 at 21:02
  • Thanks for your help, I'll take a deeper look at that. But is there any easier way to do that? – matteoh Jul 13 '16 at 21:23
  • http://stackoverflow.com/questions/18714364/android-divider-color-datepicker-dialog/23884048?noredirect=1#comment61389748_23884048. This is somthing ive tried which worked for me. Quite simple solution, just copy paste : ) – user3532232 Jul 13 '16 at 21:23
  • Thank you, but not working for me... I can't even compile. Still trying, though. – matteoh Jul 13 '16 at 21:40
  • After some research, I found [this](http://stackoverflow.com/a/29517329/3527024). So I think that a way to do what I want is to do a custom dialog box with NumberPickers in it! – matteoh Jul 13 '16 at 21:58

0 Answers0