🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
### ProgressDialog ProgressDialog与ProgressBar在UI中动态显示一个加载图标显示程序运行状态。 ProgressDialog是继承自Android.app.AlertDialog所设计的互动对话窗口,使用时,必须新建ProgressDialog对象,在运行时会弹出“对话框”作为提醒,此时应用程序后台失去焦点(即此时无法对UI组件进行操作),直到进程结束后,才会将控制权交给应用程序,如果在Activity当中不希望后台失焦,又希望提示User有某后台程序正处于忙碌阶段,那么ProgressBar就会派上用场了。 ~~~ ProgressDialog pd= new ProgressDialog(TestProgerssDialogActivity.this); // 设置pd风格 pd.setProgress(ProgressDialog.STYLE_SPINNER);//圆形 pd.setProgress(ProgressDialog.STYLE_HORIZONTAL);//水平 // 设置pd标题 pd.setTitle("提示"); // 设置pd提示 pd.setMessage("这是一个圆形进度条对话框"); // 设置pd进度条的图标 pd.setIcon(R.drawable.flag); // 设置pd的进度条是否不明确 //不滚动时,当前值在最小和最大值之间移动,一般在进行一些无法确定操作时间的任务时作为提示,明确时就是根据你的进度可以设置现在的进度值 pd.setIndeterminate(false); //pd.setProgress(m_count++); // 是否可以按回退键取消 pd.setCancelable(true); // 设置pd的一个Button pd.setButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); // 显示pd.show(); ~~~ 当有ProgressDialog时,点击back时,会首先取消ProgressDialog ,以上代码可以监听进度条被取消事件(也就是点击Back键取消ProgressDialog),此时可以在这里作一些取消后台操作的处理。 ### ProgressBar XML重要属性 ~~~ android:progressBarStyle:默认进度条样式 android:progressBarStyleHorizontal:水平样式 ~~~ 重要方法 getMax():返回这个进度条的范围的上限 getProgress():返回进度 getSecondaryProgress():返回次要进度 incrementProgressBy(int diff):指定增加的进度 isIndeterminate():指示进度条是否在不确定模式下 setIndeterminate(boolean indeterminate):设置不确定模式下 setVisibility(int v):设置该进度条是否可视 重要事件 onSizeChanged(int w, int h, int oldw, int oldh):当进度值改变时引发此事件 ~~~ <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Welcome to blog" /> <ProgressBar android:id="@+id/rectangleProgressBar" style="?android:attr/progressBarStyleHorizontal" mce_style="?android:attr/progressBarStyleHorizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:visibility="gone" /> <ProgressBar android:id="@+id/circleProgressBar" style="?android:attr/progressBarStyleLarge" mce_style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" /> <Button android:id="@+id/button" android:text="Show ProgressBar" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> ~~~ 参考: [http://www.jb51.net/article/38532.htm](http://www.jb51.net/article/38532.htm "http://www.jb51.net/article/38532.htm")