AlertDialog自定义View的用法+如何改变弹出框的大小

android系统定义了弹出框,支持我们自定义布局:

	public AlertDialog getEditCustomDialog() {
		LayoutInflater inflater = getLayoutInflater();
		View view = inflater.inflate(R.layout.custom_message_rename, null);
		AlertDialog.Builder builder = new AlertDialog.Builder(AnimationTest.this);
		builder.setView(view);
		builder.setTitle("A New Version is Available");
		return builder.create();
	}




    

    

    

        

效果图是:

 AlertDialog自定义View的用法+如何改变弹出框的大小_第1张图片



还有一种常见的样式是:



    

    

        

        
    


效果图是:

AlertDialog自定义View的用法+如何改变弹出框的大小_第2张图片


如果想改变Dialog的大小可以这样写:

					AlertDialog dialog = getCustomDialog();
					dialog.show();
					
					//一定得在show完dialog后来set属性
					WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
					lp.width = AnimationTest.this.getResources().getDimensionPixelSize(R.dimen.dialog_width);
					lp.height = AnimationTest.this.getResources().getDimensionPixelSize(R.dimen.dialog_height);
					dialog.getWindow().setAttributes(lp);


你可能感兴趣的:(android控件,android自定义控件介绍)