我正在尝试使用DialogFragment创建一个TimePickerDialog作为Android docs shows。但是,在尝试应用全息主题时,我会在执行以下操作时获得双框效果:
@Override
public Dialog onCreateDialog (Bundle savedInstanceState)
{
// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), android.R.style.Theme_Holo_Dialog, this, hourOfDay, minute, DateFormat.is24HourFormat(getActivity()));
}
如何在不出现此问题的情况下应用全息主题?
答案 0 :(得分:3)
我遇到了这个问题,我解决了这个问题。我没有使用你提出的构造函数,而是使用了ContextThemeWrapper,如下所示:
ContextThemeWrapper wrapper = new ContextThemeWrapper(getActivity(), android.R.style.Theme_Holo_Dialog);
return new TimePickerDialog(wrapper, getActivity(), hour, minute,DateFormat.is24HourFormat(getActivity()))
它对我有用:)
答案 1 :(得分:0)
有同样的问题......类TimePickerDialog
从AlertDialog
继承了自己的主题常量。您必须使用它们才能获得可预测的结果。试试这段代码:
@Override
public Dialog onCreateDialog (Bundle savedInstanceState)
{
// Create a new instance of TimePickerDialog and return it.
return new TimePickerDialog(getActivity(), TimePickerDialog.THEME_HOLO_DARK,
this, hourOfDay, minute, DateFormat.is24HourFormat(getActivity()));
}
如果您希望保持用户期望的效果,也可以使用TimePickerDialog.THEME_DEVICE_DEFAULT_DARK
。
您可以使用的常数是:
TimePickerDialog.THEME_DEVICE_DEFAULT_DARK
TimePickerDialog.THEME_DEVICE_DEFAULT_LIGHT
TimePickerDialog.THEME_HOLO_DARK
TimePickerDialog.THEME_HOLO_LIGHT
TimePickerDialog.THEME_TRADITIONAL