自定义的对话框弹窗 AlertDialog

1、先定义一个xmL文件用于,用于填充成View对象;
2,得到 AlertDialog.builder对象; AlertDialog.Builder builder = new AlertDialog.Builder(this);
3,创建一个dialog; AlertDialog dialog = builder.create();
4;填充inflate View对象; View view = View.inflate(this, R.layout.dialog_set_password, null);
5;用Dialog 设置 View对象; dialog.setView(view); //将自定义的View 显示在对话框中。
6;显示 弹窗, 自定义的View dialog.show(); //要将dialog 的设置show显示。
//在低版本中会出现,带黑边的对话框,消除黑边的办法 如下,边距设为0;
dialog.setView(view, viewSpacingLeft, viewSpacingTop, viewSpacingRight, viewSpacingBottom);

   android:inputType="textPassword"  //以密码形式显示。  password 过时了;

这种方法出现的问题是,真机测试时对话框显示的尺寸很小;

AlertDialog.Builder builder = new AlertDialog.Builder(this);
        AlertDialog dialog = builder.create();

//      View view = View.inflate(this, R.layout.dialog_set_password, null);
//      dialog.setView(view, 0, 0, 0, 0); // 将自定义的View 显示在对话框中。
        dialog.show(); // 要将dialog 的设置show显示。

改变显示对话框的尺寸方法:

AlertDialog.Builder builder = new AlertDialog.Builder(this);
        AlertDialog dialog = builder.create();
        dialog.setContentView(R.layout.dialog_set_password);
        WindowManager.LayoutParams wlp = dialog.getWindow().getAttributes(); //拿到窗口管理器 得到其属性值。
        wlp.width = (int) (getWindowManager().getDefaultDisplay().getWidth()*0.8);//  
        wlp.gravity = Gravity.CENTER;

        dialog.getWindow().setAttributes(wlp);

点击取消时,dialog 的隐藏;
dialog.dimiss();

TextUtils.isEmpty(password) //判断 Returns true if the string is null or 0-length.如果字符串为null,或者长度为0.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值