如何在轮换更改时将AlertDialog保留在DialogFragment之上

时间:2017-02-12 16:14:05

标签: android android-alertdialog android-dialogfragment

我有一个DialogFragment点击按钮会打开一个AlertDialog,在这种情况下,dialog来自此library。当我旋转设备时,我可以让AlertDialog消失,但它位于DialogFragment后面。我怎样才能使它保持在它之上?

材料对话框

mDialog = new MaterialDialog.Builder(getContext())
            .title(R.string.email_sent)
            .content(R.string.check_email)
            .inputType(InputType.TYPE_CLASS_NUMBER)
            .positiveText(R.string.send)
            .negativeText(R.string.cancel)
            .inputRange(1, 10, ContextCompat.getColor(getContext(), R.color.red_900))
            .input(R.string.activation_code, 0, new MaterialDialog.InputCallback() {
                @Override
                public void onInput(@NonNull MaterialDialog dialog, CharSequence input) {
                    dialog.dismiss();
                    int userActivationCode = Integer.parseInt(input.toString());
                    peem.setActivationCode(userActivationCode);
                    mPresenter.createActivationCodePeem(peem);
                }
            }).onNegative(new MaterialDialog.SingleButtonCallback() {
                @Override
                public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                    dialog.dismiss();
                }
            }).show();
    DisplayUtil.keepDialog(mDialog);

保持对话框的轮换更改

public static void keepDialog(MaterialDialog dialog) {
    WindowManager.LayoutParams params = new WindowManager.LayoutParams();
    params.copyFrom(dialog.getWindow().getAttributes());
    params.width = WindowManager.LayoutParams.WRAP_CONTENT;
    params.height = WindowManager.LayoutParams.WRAP_CONTENT;
    dialog.getWindow().setAttributes(params);
}

0 个答案:

没有答案