Reputation: 677
I like to change the color of DatePicker Dialog. 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 it load the dialog, it is white color background. How can I change to display color as show in the second picture?
Thanks
Upvotes: 4
Views: 9152
Reputation: 16142
As per your query you have to create custom dialog theme and set in custom_theme.xml
Now simply set as per your API
version.
First, in values add a themes.xml 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 with the name "values-v11" (Android 3.0+ ) in the res directory and put a themes.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 with the name "values-v14" (Android 4.0+) in the res directory and create a themes.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>
For More Details check out the link and follow it.
Hope you get some idea form them and solve your issue.
Good Luck.
Upvotes: 6
Reputation: 13269
Here's what I would try. For Android <= 2.3 (API 10 / v10), have your theme extend from the default android light theme, in Android 3.0 (API 11 / v11) and up, I would extend from the holo light theme. You can see how to do this here: How to use Holo.Light theme, and fall back to 'Light' on pre-honeycomb devices?
I'm not 100% sure this will change your alert dialog, since I haven't used the light theme extensively, so you may need to edit an attribute or two from the light theme to get the background of the edit text to be light.
Upvotes: 3