How to change the color of a DatePicker dialog

I like to change the color of the DatePicker dialog box. I load the dialog as

@SuppressLint("NewApi") public static class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener { @SuppressLint("NewApi") @Override public Dialog onCreateDialog(Bundle savedInstanceState) { // Use the current date as the default date in the picker final Calendar c = Calendar.getInstance(); int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH); int day = c.get(Calendar.DAY_OF_MONTH); // Create a new instance of DatePickerDialog and return it return new DatePickerDialog(getActivity(), this, year, month, day); } public void onDateSet(DatePicker view, int year, int month, int day) { // Do something with the date chosen by the user } } @SuppressLint("NewApi") public void showDatePickerDialog(View v) { DialogFragment newFragment = new DatePickerFragment(); newFragment.show(getFragmentManager(), "datePicker");//show(getSupportFragmentManager(), "datePicker"); } 

When loading a dialog box, it is white. How to change the display color in the second image? Thanks enter image description hereenter image description here

+4
source share
2 answers

According to your request, you need to create your own dialogue topic and install in custom_theme.xml Now just install it according to your version of the API .

First, add theme.xml in the values ​​like this:

 <?xml version="1.0" encoding="utf-8"?> <resources> <style name="MyAppTheme" parent="@android:style/Theme.Light.NoTitleBar"> <!-- Any customizations for your app running on pre-3.0 devices here --> </style> </resources> 

Then create a directory called "values-v11" (Android 3.0+) in the res directory and put theme.xml like this

 <?xml version="1.0" encoding="utf-8"?> <resources> <style name="MyAppTheme" parent="@android:style/Theme.Holo.Light"> <!-- Any customizations for your app running on 3.0+ devices here --> </style> </resources> 

Finally, create a directory called "values-v14" (Android 4.0+) in the res directory and create a theme.xml

 <?xml version="1.0" encoding="utf-8"?> <resources> <style name="MyAppTheme" parent="@android:style/Theme.DeviceDefault.Light.NoActionBar"> <!-- Any customizations for your app running on 4.0+ devices here --> </style> </resources> 

More ... check the link and follow it.

I hope you get an idea about them and solve your problem.

Good luck.

+6
source

Here is what I would try. For Android <= 2.3 (API 10 / v10), your theme extends from the default Android theme theme, in Android 3.0 (API 11 / v11) and above, I would extend from a bare light theme. You can see how to do it here: How to use the Holo.Light theme and return to the β€œLight” on devices with pre-cellular communication?

I am not 100% sure that this will change your notification dialog, since I did not use the light theme extensively, so you may need to edit one or two attributes from the light theme to get the background of the editing text to be light.

+3
source

All Articles