版权声明:https://blog.csdn.net/qq_40881680 https://blog.csdn.net/qq_40881680/article/details/80908279
1:普通消息对话框
效果图:
java代码案例:
AlertDialog.Builder builder = new AlertDialog.Builder(day1.this);
builder.setTitle("警告!");
builder.setIcon(R.mipmap.ic_launcher);//加入图片
builder.setMessage("请确认是否退出!");//设置内容
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {//确定按钮事件
@Override
public void onClick(DialogInterface dialogInterface, int i) {//点击事件
Toast.makeText(day1.this, "确定按钮", Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {//取消按钮事件
@Override
public void onClick(DialogInterface dialogInterface, int i) {//点击事件
Toast.makeText(day1.this, "取消按钮", Toast.LENGTH_SHORT).show();
}
});
builder.create().show();//显示
2:进度条消息对话框
效果图1(精确):
效果图2(模糊):
一个为模糊式的进度条,一个是精确的进度条,模糊进度条用到setIndeterminate()方法来设置是否为模糊进度条
精确式代码案例:
ProgressDialog dialog=new ProgressDialog(day1.this);
dialog.setTitle("精确式进度条");
dialog.setMessage("进度:(精确)");
dialog.setIcon(R.mipmap.ic_launcher);
dialog.setMax(100);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.show();
dialog.setProgress(10);//当前进度
模糊式代码案例:
ProgressDialog dialog=new ProgressDialog(day1.this);
dialog.setTitle("模糊式进度条");
dialog.setMessage("进度:(模糊)");
dialog.setIcon(R.mipmap.ic_launcher);
dialog.setMax(100);
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
dialog.show();
dialog.setIndeterminate(true);//设置为模糊式