屏幕旋转后恢复对话框

Les*_*ter 1 android android-alertdialog material-design

我有2个edittexts的对话框(来自这个库的材料对话框 ).在我旋转后,设备活动被破坏并且对话框也是如此.我知道edittext有自动保存输入文本,但我怎么能禁止对话被破坏?

 MaterialDialog dialog = new MaterialDialog.Builder(context).customView(R.layout.dialog_edit_point_info, false)
            .positiveText(R.string.ok).negativeText(R.string.cancel)
            .positiveColorRes(R.color.dark_blue).negativeColorRes(R.color.black)
            .iconRes(R.drawable.ic_marker_location)
            .autoDismiss(false)
            .title(R.string.edit_title_dialog).callback(callback).build;
Run Code Online (Sandbox Code Playgroud)

Chr*_*her 5

将对话框放在DialogFragment中:

public static class MyAlertDialogFragment extends DialogFragment {

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    MaterialDialog dialog = new MaterialDialog.Builder(context).customView(R.layout.dialog_edit_point_info, false)
        .positiveText(R.string.ok).negativeText(R.string.cancel)
        .positiveColorRes(R.color.dark_blue).negativeColorRes(R.color.black)
        .iconRes(R.drawable.ic_marker_location)
        .autoDismiss(false)
        .title(R.string.edit_title_dialog).callback(callback).build();

}
}
Run Code Online (Sandbox Code Playgroud)

要调用对话框:

void showDialog() {
    DialogFragment newFragment = new MyAlertDialogFragment();
    newFragment.show(getFragmentManager(), "dialog");
}
Run Code Online (Sandbox Code Playgroud)

您可以在此处找到更多信息:http://developer.android.com/reference/android/app/DialogFragment.html

如果您使用Support-Libs,请使用相应的支持类:http://developer.android.com/reference/android/support/v4/app/DialogFragment.html