旋转

时间:2018-06-15 16:37:01

标签: android android-dialogfragment screen-rotation

我在DialogFragment中遇到了一个奇怪的问题

问题是,当显示DialogFragment然后更改设备方向然后单击取消按钮时,白色框(显示消息和按钮的那个)消失但透明的黑色背景仍然存在,应用程序无法响应用户输入。删除该背景的唯一方法是点击硬件后退按钮 -

我附上一些图片

This is the first time DialogFragment is shown

Here, the device orientation has changed with no issues

The issue comes here, when i click on cancel button. As you can see the white box got closed but that black transparent background is still there, and user input is not working. By hitting hardware backbutton, black transparent background disappears and app works again as expected.

这是DialogFragment的类

public class MyAlertDialogFragment  extends DialogFragment {

public MyAlertDialogFragment() {

}

public static MyAlertDialogFragment newInstance(String title) {
    MyAlertDialogFragment frag = new MyAlertDialogFragment();
    Bundle args = new Bundle();
    args.putString("title", title);
    frag.setArguments(args);
    return frag;
}

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    String title = getArguments().getString("title");
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
    alertDialogBuilder.setTitle(title);
    alertDialogBuilder.setMessage("Are you sure you want to delete the selected item?");
    alertDialogBuilder.setPositiveButton("Delete",  new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // on success
        }
    });
    alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (dialog != null) {
                dialog.dismiss();
            }
        }

    });

    return alertDialogBuilder.create();
}

}

有人可以帮我解决这个问题吗? :)

提前致谢

我为我的英语道歉:/

0 个答案:

没有答案