AlertDialog.Builder builder = new Builder(mContext); builder.setTitle("更新进度"); final LayoutInflater inflater = LayoutInflater.from(mContext); View v = inflater.inflate(R.layout.progress, null); mProgress = (ProgressBar) v.findViewById(R.id.progress); builder.setView(v);//此处设置自定义布局 downloadDialog = builder.create(); downloadDialog.show(); downloadDialog.getWindow().setLayout(300, 200);//此处设置位置窗体大小
注意设置位置需要在dialog调用show()方法以后,要不然没有效果i改变
另外dialog也可以设置窗体位置 具体代码为
menuDialog = new AlertDialog.Builder(this).create(); Window mWindow = menuDialog.getWindow(); WindowManager.LayoutParams lp = mWindow.getAttributes(); lp.x = 10; //新位置X坐标 lp.y = 120; //新位置Y坐标 menuDialog.onWindowAttributesChanged(lp); menuDialog.show();