自定义对话框

public void MyDialog(){
//TODO 1:构建者
AlertDialog.Builder builder=new AlertDialog.Builder(this);
//TODO 2:设置属性
builder.setTitle("老婆");
builder.setIcon(R.mipmap.y);
//TODO 3:设置内部视图
ImageView imageView = new ImageView(this);
imageView.setImageResource(R.mipmap.u);
builder.setView(imageView);
//TODO 设置确定按钮
builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "你点击了确认", Toast.LENGTH_SHORT).show();
}
});
//TODO 设置取消按钮
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "你点击了取消", Toast.LENGTH_SHORT).show();
}
});
//TODO 3:使用建造者创建对话框
AlertDialog alertDialog = builder.create();
//TODO 4:显示
alertDialog.show();
}
--------------------- 

posted @ 2019-08-01 19:28  李艳艳665  阅读(95)  评论(0编辑  收藏  举报