from:http://byandby.iteye.com/blog/817214

显然要定义对话框进度条就要用ProgressDialog,首先我们需要创建ProgressDialog对象,当然这里同样使用了线程来控制进度条显示,另外可以使用以下方法来设置ProgressDialog。 
  setProgressStyle:设置进度条风格,风格为圆形,旋转的。 
  setTitlt:设置ProgressDialog 标题 
  setMessage:设置ProgressDialog提示信息; 
  setIcon:设置ProgressDialog标题图标; 
  setIndeterminate:设置ProgressDialog 的进度条是否不明确; 
  setCancelable:设置ProgressDialog 是否可以按返回键取消; 
  setButton:设置ProgressDialog 的一个Button(需要监听Button事件); 
  show:显示ProgressDialog。

首先还是让我们看看运行效果吧

 
 

下面先来看看布局文件 
<?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="@string/hello" 
    /> 
<Button 
android:id="@+id/Button01" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="圆形进度条"/>

<Button 
android:id="@+id/Button02" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="长形进度条"/> 
</LinearLayout>

Activity01

    1. package xiaohang.zhimeng;
    2. import android.app.Activity;
    3. import android.app.ProgressDialog;
    4. import android.content.DialogInterface;
    5. import android.os.Bundle;
    6. import android.view.View;
    7. import android.view.View.OnClickListener;
    8. import android.widget.Button;
    9. public class Activity01 extends Activity {
    10. private Button xhButton01, xhButton02;
    11. int xh_count = 0;
    12. // 声明进度条对话框
    13. ProgressDialog xh_pDialog;
    14. @Override
    15. public void onCreate(Bundle savedInstanceState) {
    16. super.onCreate(savedInstanceState);
    17. setContentView(R.layout.main);
    18. // 得到按钮对象
    19. xhButton01 = (Button) findViewById(R.id.Button01);
    20. xhButton02 = (Button) findViewById(R.id.Button02);
    21. // 设置xhButton01的事件监听
    22. xhButton01.setOnClickListener(new OnClickListener() {
    23. @Override
    24. public void onClick(View v) {
    25. // 创建ProgressDialog对象
    26. xh_pDialog = new ProgressDialog(Activity01.this);
    27. // 设置进度条风格,风格为圆形,旋转的
    28. xh_pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    29. // 设置ProgressDialog 标题
    30. xh_pDialog.setTitle("提示");
    31. // 设置ProgressDialog提示信息
    32. xh_pDialog.setMessage("这是一个圆形进度条对话框");
    33. // 设置ProgressDialog标题图标
    34. xh_pDialog.setIcon(R.drawable.img1);
    35. // 设置ProgressDialog 的进度条是否不明确 false 就是不设置为不明确
    36. xh_pDialog.setIndeterminate(false);
    37. // 设置ProgressDialog 是否可以按退回键取消
    38. xh_pDialog.setCancelable(true);
    39. // 设置ProgressDialog 的一个Button
    40. xh_pDialog.setButton("确定", new Bt1DialogListener());
    41. // 让ProgressDialog显示
    42. xh_pDialog.show();
    43. }
    44. });
    45. // 设置xhButton02的事件监听
    46. xhButton02.setOnClickListener(new Button.OnClickListener() {
    47. @Override
    48. public void onClick(View v) {
    49. xh_count = 0;
    50. // 创建ProgressDialog对象
    51. xh_pDialog = new ProgressDialog(Activity01.this);
    52. // 设置进度条风格,风格为圆形,旋转的
    53. xh_pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    54. // 设置ProgressDialog 标题
    55. xh_pDialog.setTitle("提示");
    56. // 设置ProgressDialog提示信息
    57. xh_pDialog.setMessage("这是一个长形进度条对话框");
    58. // 设置ProgressDialog标题图标
    59. xh_pDialog.setIcon(R.drawable.img2);
    60. // 设置ProgressDialog 的进度条是否不明确 false 就是不设置为不明确
    61. xh_pDialog.setIndeterminate(false);
    62. // 设置ProgressDialog 进度条进度
    63. xh_pDialog.setProgress(100);
    64. // 设置ProgressDialog 是否可以按退回键取消
    65. xh_pDialog.setCancelable(true);
    66. // 让ProgressDialog显示
    67. xh_pDialog.show();
    68. new Thread() {
    69. @Override
    70. public void run() {
    71. try {
    72. while (xh_count <= 100) {
    73. // 由线程来控制进度
    74. xh_pDialog.setProgress(xh_count++);
    75. Thread.sleep(100);
    76. }
    77. xh_pDialog.cancel();
    78. } catch (Exception e) {
    79. xh_pDialog.cancel();
    80. }
    81. }
    82. }.start();
    83. }
    84. });
    85. }
    86. // xhButton01的监听器类
    87. class Bt1DialogListener implements DialogInterface.OnClickListener {
    88. @Override
    89. public void onClick(DialogInterface dialog, int which) {
    90. // 点击“确定”按钮取消对话框
    91. dialog.cancel();
    92. }
    93. }
    94. }

android 对话框中的进度条 (ProgressDialog)的更多相关文章

  1. C#.NET中使用BackgroundWorker在模态对话框中显示进度条

    这里是一个示例,其中展示了如何使用Backgroundworker对象在模态对话框中显示后台操作的实时进度条. 首先是主窗体代码: using System; using System.Collect ...

  2. 关于JFace中的进度条对话框(ProgressMonitorDialog类)

    在Windows操作系统中,最常用的进度条对话框就是文件复制时的弹出框,如果想让用户愉快的使用你开发 的软件,那么在执行某个较长时间的操作时候,就应该弹出一个进度条提示框,告诉用户程序正在做什么. 做 ...

  3. Android 中带有进度条效果的按钮(Button)

    安卓中带有进度条效果的按钮,如下图: 1.布局文件如下activity_main.xml <RelativeLayout xmlns:android="http://schemas.a ...

  4. Android 使用ProgressBar实现进度条

    ProgressBar简介ProgressBar是进度条组件,通常用于向用户展示某个耗时操作完成的进度,而不让用户感觉是程序失去了响应,从而更好地提升用户界面的友好型. 课程目标(1)制定Progre ...

  5. Android学习笔记- ProgressBar(进度条)

    本节引言: 本节给大家带来的是Android基本UI控件中的ProgressBar(进度条),ProgressBar的应用场景很多,比如 用户登录时,后台在发请求,以及等待服务器返回信息,这个时候会用 ...

  6. Xamarin XAML语言教程Xamarin.Forms中构建进度条

    Xamarin XAML语言教程Xamarin.Forms中构建进度条 ProgressBar被称为进度条,它类似于没有滑块的滑块控件.进度条总是水平放置的.本节将讲解如何使用进度条. 注意:进度条在 ...

  7. Android学习笔记(24):进度条组件ProgressBar及其子类

    ProgressBar作为进度条组件使用,它还派生了SeekBar(拖动条)和RatingBar(星级评分条). ProgressBar支持的XML属性: Attribute Name Related ...

  8. 如何在UIAlertView中显示进度条

    今天这个问题是,在一个iPhone程序中,我要在后台做大量的数据处理,希望在界面上显示一个进度条(Progress Bar)使得用户了解处理进度.这个进度条应该是在一个模态的窗口中,使界 今天这个问题 ...

  9. CListCtrl控件中显示进度条

    CListCtrl控件的subitem中显示进度条 http://www.codeproject.com/Articles/6813/List-Control-Extended-for-Progres ...

随机推荐

  1. LINUX内核升级-更新网卡驱动

    因项目需要,将当前内核(2.6.32-220.el6.x86_64)升级到目标内核(2.6.33-110.el6.x86_64),但是编译的目标 内核(2.6.33-110.el6.x86_64)的对 ...

  2. flask/sqlalchemy - OperationalError: (sqlite3.OperationalError) no such table

    狗书第五章 记得要先创建表 执行 db.create_all()语句来创建表 https://segmentfault.com/q/1010000005794140

  3. 【Mac + Appium + Python3.6学习(二)】之Android自动化测试,appium-desktop配置和简易自动化测试脚本

    上一篇文章介绍安装appium测试环境,这一片研究介绍如何测试Android自动化. 上一篇地址:<[Mac + Appium学习(一)]之安装Appium环境> 这一篇参考:<Ma ...

  4. 【转】Monkey测试6-Monkey Test Log

    Moneky Test Log 分析: 首先用一个最简单的例子分析:monkey --pct-trackball 0 --throttle 100 -v 500/*p参数: 表示指定测试的程序/*v参 ...

  5. servelet 直接输出内容

    package helloworld; import java.io.IOException; import javax.servlet.ServletException; import javax. ...

  6. 嵌入式开发之davinci--- 8148/8168/8127 中swms、Mosaic’s、display 显示pal 模式

    (1) (2) (3) (4) -------------------------author:pkf ------------------------------time:2-3 --------- ...

  7. Python Numpy ValueError: data type must provide an itemsize

    天朝网络锁国,百度找了半个小时找不出来原因,只能谷歌 谷歌第一条就是,顿时感觉幸福感来的太突然 原因是输入的矩阵均是字符串(从文件里读的) 那么就需要批量转数组,一行一行的转. 下面是我的代码: ro ...

  8. 用Flex实现常见的几种布局

    用Flex实现常见的几种布局 1.水平,垂直居中. <style type="text/css"> .container{ display: flex; width: ...

  9. java httpSession 设置超时时间

    1.设置过期时间方式一:在tomcat/conf/web.xml下加入一下内容 <session-config> <session-timeout>90</session ...

  10. 41个Web开发者必须收藏的JavaScript实用技巧

    1. 将彻底屏蔽鼠标右键 oncontextmenu=”window.event.returnValue=false” < table border oncontextmenu=return(f ...