Android 基础控件 AdminDialog

创建

LayoutInflater inflater = LayoutInflater.from(getContext());
View view = inflater.inflate(R.layout.exitdialog, null);
EditText enterValue = view.findViewById(R.id.editPassword);
AlertDialog AdminDialog;
adminDialog = new AlertDialog.Builder(getContext()).setView(view).setTitle("请输入兑换码:")
        .setIcon(android.R.drawable.ic_dialog_info)
        .setCancelable(false)
        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int i) {
            }
        })
        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int i) {
            }
        })
        .create();
adminDialog.show();

手动关闭弹窗

/**
 * 手动控制弹窗的显示和隐藏
 * @param dialog
 * @param visible
 */
private void setBindingCodeDialogVisible(DialogInterface dialog, boolean visible) {
    if (visible) {
        try {
            //不关闭
            Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
            field.setAccessible(true);
            field.set(dialog, false);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        //关闭对话框
        try {
            Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
            field.setAccessible(true);
            field.set(dialog, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        dialog.dismiss();
    }
}


你可能感兴趣的:(Android 基础控件 AdminDialog)