前面两讲我们讲解了AlertDialog的一些基本使用方法,下面我在来学习对话框的其他使用方法,ProgressDialog 和自定义对话框。
1. ProgressDialog进度条的使用。
ProgressDialog是AlertDialog的一个子类,主要是显示一个旋转动画形式的进度对话框,或者是一个进度条,它一般表示任务在执行过程中的进度显示,这种对话框还可提供一个按钮,比如说用于取消下载的按钮。通过调用ProgressDialog.show()来显示这种对话框。
查看ProgressDialog的API文档,进度对话框可以通过back键取消,进度范围在 0~10000之间,一般是在加载网络数据的时候使用。以后在做百分比的时候
一般在这边要做一个下载量和百分比的一个公式的换算。查看方法 public void setProgressStyle (int style),这个方法用来显示对话框的样式。查看该API下两个常量,如下图所示:
第一种是用来做用来下载的进度,后面一种主要是延时的操作。
使用方式如下说明:To show the progression with an animated progress bar:1. Initialize the ProgressDialog with the class constructor, ProgressDialog(Context).2. Set the progress style to "STYLE_HORIZONTAL" with setProgressStyle(int) and set any other properties, such as the message.3. When you're ready to show the dialog, call show() or return the ProgressDialog from the onCreateDialog(int) callback.4. You