AlertDialog alertDialog;
AlertDialog.Builder builder;
//实例化 LayoutInflater
LayoutInflater inflater=(LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
//main1为对话框布局
View Layout=inflater.inflate(R.layout.main1, null);
TextView text=(TextView)Layout.findViewById(R.id.viewpaper1);
ImageView iamge=(ImageView)Layout.findViewById(R.id.viewpaper);
iamge.setImageResource(R.drawable.ic_launcher);
builder=new AlertDialog.Builder(this);
alertDialog=builder.create();
alertDialog.setView(Layout);
// 调整对话框的位置
Window mWindow=alertDialog.getWindow();
WindowManager.LayoutParams lp=mWindow.getAttributes();
lp.x=0;
lp.y=50;
alertDialog.onWindowAttributesChanged(lp);
alertDialog.show();
本文将指导您如何在Android中创建自定义AlertDialog布局,并详细解释如何调整其显示位置,包括实例代码演示。
941

被折叠的 条评论
为什么被折叠?



