I have implemented a TimePickerDialog
using the following code as given in developer.android.com:
public static class TimePickerFragment extends DialogFragment
implements TimePickerDialog.OnTimeSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current time as the default values for the picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), this, hour, minute,
DateFormat.is24HourFormat(getActivity()));
}
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// Do something with the time chosen by the user
}
}
I get a dialog like this one:
I want to change the theme of the TimePickerDialog
to go with the AppTheme
which extends an AppCompat
theme. When i do use the other constructor as told by some, the theme works, but the Dialog
goes fullscreen. The code i used for that was:
// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), R.style.AppTheme, this, hour, minute,
DateFormat.is24HourFormat(getActivity()));
I get this:
How do i go about this? - I want the Dialog
to remain the same, but change only the accent colors. Thanks!
You have to use Theme.AppCompat.Light.Dialog
as Parent Theme
You need to define Dialog
theme in styles.xml
.
<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">@color/purple</item>
<item name="colorControlNormal">@color/orange</item>
</style>
then use it like this:
// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), R.style.DialogTheme, this, hour, minute,
DateFormat.is24HourFormat(getActivity()));
I hope it helps you.
You also may override the getTheme method like this:
public class TimePickerFragment extends DialogFragment {
...
@Override
public int getTheme() {
return R.style.MyDialogTheme;
}
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With