android - 自定义对话框

一、自定义对话框

  1. 自定义.xml布局
  2. 获取LayoutInflater对象
  3. 调用inflate()方法获取View对象
  4. 调用Builder对象的setView()方法设置View
  5. 获取输入内容或者监听点击事件等
Dialog dialog;
    public void customBtnClick(View view){
        LayoutInflater inflater = LayoutInflater.from(this);
        View myView = inflater.inflate(R.layout.activity_custom_dialog, null);
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setView(myView);
        myView.findViewById(R.id.custom_dialog_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
                Toast.makeText(custom_dialog01.this, "点击了确定", Toast.LENGTH_SHORT).show();
            }
        });
        dialog = builder.create();
        dialog.show();
    }




    

        
        
        

android - 自定义对话框_第1张图片

二、使用PopupWindow的实现步骤

    1. 自定义.xml布局
    1. 获取LayoutInflater对象
    1. 调用inflate()方法和获取View对象
    1. 创建PopupWindow对象
    1. 调用PopupWindow的showAsDropDown或者showAsLocation方法显示对话框窗口

三、Activity变Dialog样式,去除标题

你可能感兴趣的:(android)