使用AlertDialog可以实现如下对话框
案例
布局问文件就加了几个Button,我直接上Java代码了
- 实现显示带取消,确定按钮的对话框按钮
Button showDialogOne = findViewById(R.id.showDialog_one);
showDialogOne.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
AlertDialog alertDialog = new
AlertDialog.Builder(MainActivity.this).create();
//创建AlertDialog对象
alertDialog.setIcon(R.drawable.apple);//设置图标
alertDialog.setTitle("一个战5渣:");//设置标题
alertDialog.setTitle("苟活性命于互联网,我太难了,是吧?");
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
"否", new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(
MainActivity.this, "您单击了否按钮",
Toast.LENGTH_SHORT).show();
}
});//取消按钮
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE,
"是", new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(
MainActivity.this, "您单击了是按钮",
Toast.LENGTH_SHORT).show();
}
});//取消按钮
alertDialog.show();
}
});
效果:
- 显示带列表的对话框按钮