原文网址:http://blog.csdn.net/sjf0115/article/details/7255280

版权声明:本文为博主原创文章,未经博主允许不得转载。

<1>简介

ProgressDialog是AlertDialog类的一个扩展,可以为一个未定义进度的任务显示一个旋转轮形状的进度动画,或者为一个指定进度的任务显示一个进度条。

一个对话框中显示一个进步指标和一个可选的文本信息或一个视图。只有文本信息或一个视图,可以同时使用。

对话框可以按back键取消。

<2>方法

setProgressStyle()     设置进度条风格

setTitle()    设置ProgressDialog 标题

setMessage()    设置ProgressDialog 提示信息

setIcon()    设置ProgressDialog 标题图标

setIndeterminate()  设置ProgressDialog 的进度条是否不明确

setCancelable()   设置ProgressDialog 是否可以按退回按键取消

setButton()    设置ProgressDialog 的一个Button

setProgress() 设置ProgressDialog 进度条进度

show()  显示ProgressDialog

<3>范例

  1. package com.yarin.android.Examples_04_24;
  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. {
  11. private Button Button1 = null;
  12. private Button Button2 = null;
  13. int count = 0;
  14. //声明进度条对话框
  15. ProgressDialog progressDialog = null;
  16. /** Called when the activity is first created. */
  17. @Override
  18. public void onCreate(Bundle savedInstanceState)
  19. {
  20. super.onCreate(savedInstanceState);
  21. setContentView(R.layout.main);
  22. //得到按钮对象
  23. Button1 = (Button)findViewById(R.id.Button01);
  24. Button2 = (Button)findViewById(R.id.Button02);
  25. //设置mButton01的事件监听
  26. Button1.setOnClickListener(new Button1Listener());
  27. //设置mButton02的事件监听
  28. Button2.setOnClickListener(new Button2Listener());
  29. }
  30. private class Button1Listener implements OnClickListener{
  31. public void onClick(View v) {
  32. //创建ProgressDialog对象
  33. progressDialog = new ProgressDialog(Activity01.this);
  34. // 设置进度条风格,风格为圆形,旋转的
  35. progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
  36. // 设置ProgressDialog 标题
  37. progressDialog.setTitle("提示");
  38. // 设置ProgressDialog 提示信息
  39. progressDialog.setMessage("这是一个圆形进度条对话框");
  40. // 设置ProgressDialog 标题图标
  41. progressDialog.setIcon(R.drawable.a);
  42. // 设置ProgressDialog 的进度条是否不明确
  43. progressDialog.setIndeterminate(false);
  44. // 设置ProgressDialog 是否可以按退回按键取消
  45. progressDialog.setCancelable(true);
  46. //设置ProgressDialog 的一个Button
  47. progressDialog.setButton("确定", new SureButtonListener());
  48. // 让ProgressDialog显示
  49. progressDialog.show();
  50. }
  51. }
  52. //Dialog中确定按钮的监听器
  53. private class SureButtonListener implements android.content.DialogInterface.OnClickListener{
  54. public void onClick(DialogInterface dialog, int which) {
  55. //点击“确定按钮”取消对话框
  56. dialog.cancel();
  57. }
  58. }
  59. private class Button2Listener implements OnClickListener{
  60. public void onClick(View v) {
  61. count = 0;
  62. // 创建ProgressDialog对象
  63. progressDialog = new ProgressDialog(Activity01.this);
  64. // 设置进度条风格,风格为长形
  65. progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
  66. // 设置ProgressDialog 标题
  67. progressDialog.setTitle("提示");
  68. // 设置ProgressDialog 提示信息
  69. progressDialog.setMessage("这是一个长形对话框进度条");
  70. // 设置ProgressDialog 标题图标
  71. progressDialog.setIcon(R.drawable.a);
  72. // 设置ProgressDialog 进度条进度
  73. progressDialog.setProgress(100);     《==应该改为 progressDialog.setMax(100)
  74. // 设置ProgressDialog 的进度条是否不明确
  75. progressDialog.setIndeterminate(false);
  76. // 设置ProgressDialog 是否可以按退回按键取消
  77. progressDialog.setCancelable(true);
  78. // 让ProgressDialog显示
  79. progressDialog.show();
  80. new Thread()
  81. {
  82. public void run()
  83. {
  84. try
  85. {
  86. while (count <= 100)
  87. {
  88. // 由线程来控制进度。
  89. progressDialog.setProgress(count++);
  90. Thread.sleep(100);
  91. }
  92. progressDialog.cancel();
  93. }
  94. catch (InterruptedException e)
  95. {
  96. progressDialog.cancel();
  97. }
  98. }
  99. }.start();
  100. }
  101. }
  102. }
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. >
  7. <Button
  8. android:id="@+id/Button01"
  9. android:layout_width="wrap_content"
  10. android:layout_height="wrap_content"
  11. android:text="圆形进度条" />
  12. <Button
  13. android:id="@+id/Button02"
  14. android:layout_width="wrap_content"
  15. android:layout_height="wrap_content"
  16. android:text="长形进度条" />
  17. </LinearLayout>

【转】Android ProgressDialog的使用的更多相关文章

  1. 【转】Android ProgressDialog的使用2

    原文网址:http://www.cnblogs.com/hnrainll/archive/2012/03/28/2420908.html <?xml version="1.0" ...

  2. Android ProgressDialog 加载进度

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...

  3. android progressdialog 对话框试用实例

    ProgressDialog 跟AlertDialog用法差不多,不同的是:ProgressDialog 显示的是一种"加载中"的效果,android 中 ProgressDial ...

  4. android ProgressDialog 正在载...Loading...

    final ProgressDialog pd = new ProgressDialog(mContext); pd.setMessage("正在加载..."); pd.show( ...

  5. Android——ProgressDialog 进度条对话框

    public class ProgressDialogActivity extends Activity {    private Button btn_large_pd, btn_horizonta ...

  6. Android ProgressDialog 简单实用

    ProgressDialog progressDialog; @SuppressLint("HandlerLeak") Handler handler1 = new Handler ...

  7. android:ProgressDialog控件

    ProgressDialog 和 AlertDialog 有点类似,都可以在界面上弹出一个对话框,都能够屏蔽 掉其他控件的交互能力.不同的是,ProgressDialog 会在对话框中显示一个进度条, ...

  8. 自定义android ProgressDialog

    Android系统自己提供的UI的都是比较难看的,开发中经常用到自定义对话框,下面分享个最近项目中使用的加载框.   下面是源代码,主要的原理就是准备几个图片,然后循环播放. MainActivity ...

  9. Android学习笔记_81_Android ProgressDialog ProgressBar 各种效果

    1,弹出Dialog 屏幕不变暗. 创建一个样式就OK了:在styles.xml文件里添加样式: 1, <style name="dialog" parent="@ ...

随机推荐

  1. SAMBA用户访问指定的目录

    指定某个用户访问一个特定的共享文件夹sfx 用户可以访问abc目录 别的用户不可以访问abc目录 先创建一个用户命令useradd sfx 创建一个smbpasswd用户 在创建这个用户时要先创建一个 ...

  2. JAVA时间日期处理类,主要用来遍历两个日期之间的每一天。

    /** * * 文 件 名: AccountDate.java * * 创建时间: 2008-11-18 * * Email : **@163.com */ import java.text.Deci ...

  3. UITableView编写可以添加,删除,移动的物品栏(二)

    MyTableViewCell.h文件(自定义ViewCell)的内容: MyTableViewCell.m的内容

  4. JS常用的7中跨域方式总结

    javascript跨域有两种情况:  1.基于同一父域的子域之间,如:a.c.com和b.c.com  2.基于不同的父域之间,如:www.a.com和www.b.com  3.端口的不同,如:ww ...

  5. 使用 fn 标签 解决字数过多时用省略号代替 .............................

    list列表单条记录某字段大于10就后面添加省略号(如:内容只是显示开始的10个字,后面的用省略号代替) 在list列表中单条记录某字段大于10就后面添加省略号, 首先引入 jstl标签: <% ...

  6. php5.4安装ecshopphp5.4问题及解决

    includes/cls_template.php line422 将 $tag_sel = array_shift(explode(" ", $tag)); 这句话拆开为两句. $tag_exp = ...

  7. web常用正则表达式

    1. 平时做网站经常要用正则表达式,下面是一些讲解和例子,仅供大家参考和修改使用: 2. "^\d+$" //非负整数(正整数 + 0) 3. "^[0-9]*[1-9] ...

  8. 快速搭建高速稳定三层B/S架构

  9. net Core 通过 Ef Core 访问、管理Mysql

    net Core 通过 Ef Core 访问.管理Mysql 本文地址:http://www.cnblogs.com/likeli/p/5910524.html 环境 dotnet Core版本:1. ...

  10. vim设置

    折腾一下vim http://www.cnblogs.com/zhangsf/archive/2013/06/13/3134409.html