AlertDialog

1.基本显示

clipboard.png

clipboard2.png

2.显示自定义View

 View view=View.inflate(this,R.layout.login_layout,null);
        final EditText etEmail=(EditText)view.findViewById(R.id.layout_login_et_email);
        final EditText etPwd=(EditText)view.findViewById(R.id.layout_login_et_Passwords);

        AlertDialog dialog=new AlertDialog.Builder(MainActivity.this)
                .setTitle("Login")
                .setView(view)
                .setNegativeButton("Cancel", null)
                .setPositiveButton("Login",null)
                .create();

        dialog.setCancelable(false); //点击Dialog外围区域,不可以关闭Dialog
        dialog.show();

        // 点击 PositiveButton 按钮后,不会关闭Dialog
        // 注意需要写在 sho
        dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
Last modification:January 14th, 2020 at 08:08 pm