我TimePickerDialog
使用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 }
}
我得到一个像这样的对话框:
我想改变主题,TimePickerDialog
以AppTheme
扩展AppCompat
主题.当我使用其他构造函数时,一些人说,主题有效,但是Dialog
全屏.我用的代码是:
// Create a new instance of TimePickerDialog and return it return new TimePickerDialog(getActivity(), R.style.AppTheme, this, hour, minute, DateFormat.is24HourFormat(getActivity()));
我明白了:
我该怎么做?- 我希望Dialog
保持不变,但只改变强调色.谢谢!
你必须使用Theme.AppCompat.Light.Dialog
asParent Theme
你需要定义Dialog
主题styles.xml
.
然后像这样使用它:
// Create a new instance of TimePickerDialog and return it return new TimePickerDialog(getActivity(), R.style.DialogTheme, this, hour, minute, DateFormat.is24HourFormat(getActivity()));
我希望它对你有所帮助.