美文网首页
Android 基础控件 AdminDialog

Android 基础控件 AdminDialog

作者: sssssss_ | 来源:发表于2022-06-06 12:02 被阅读0次

    创建

    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

          本文链接:https://www.haomeiwen.com/subject/tbhjmrtx.html