只需使用DatePicker对话框,当您在弹出对话框中更改方向时,它将给您一个错误。如何禁用方向更改?
public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
private Task mTask;
private static final String DIALOG_DATE = "Date";
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
int year;
int month;
int day;
final Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(getActivity(), this, year, month, day);
}
答案 0 :(得分:1)
覆盖DialogFramgent中的show(),并在调用它时禁用Activity的方向。让你的DilagFragment实现DismissListener,当调用onDismiss时,重新启用方向
@Override
public void show(FragmentManager fm, String tag) {
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
super.show(fm, tag);
}