0

只需使用 DatePicker Dialog,当您在弹出对话框中更改方向时,它会给您一个错误。如何禁用方向更改?

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);
    }
4

1 回答 1

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);
}
于 2013-06-02T08:04:20.237 回答