APP应用中经常会下载某些东西,这里面有涉及到进度对话框,今天来学习下。

首先,布局里放进两个按钮,点击一个显示条形进度条,另一个显示圆形进度条。代码如下:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"> <Button
android:id="@+id/progress"
android:layout_width="128dp"
android:layout_height="wrap_content"
android:text="条形进度条" /> <Button
android:id="@+id/circle"
android:layout_width="128dp"
android:layout_height="wrap_content"
android:text="圆形进度条" /> </LinearLayout>

显示效果:

修改MainActivity.java文件:

 package com.example.progressdialog;

 import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button; public class MainActivity extends Activity { private Button m_btnProgress = null;
private Button m_btnCircle = null;
private ProgressDialog pDialog = null;
private int iCount = 0; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); m_btnProgress = (Button) findViewById(R.id.progress);
m_btnCircle = (Button) findViewById(R.id.circle); m_btnProgress.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
iCount = 0;
pDialog = new ProgressDialog(MainActivity.this); // 设置进度条风格,风格为长形
pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); // 设置ProgressDialog 标题
pDialog.setTitle("条形进度条"); // 设置ProgressDialog 提示信息
pDialog.setMessage("正在下载中……"); // 设置ProgressDialog 标题图标
pDialog.setIcon(R.drawable.ic_launcher); // 设置ProgressDialog 进度条进度
pDialog.setProgress(100); // 设置ProgressDialog 的进度条是否不明确
pDialog.setIndeterminate(false); // 设置ProgressDialog 是否可以按退回按键取消
pDialog.setCancelable(true); // 让ProgressDialog显示
pDialog.show(); new Thread() {
public void run() {
try {
while (iCount <= 100) {
// 由线程来控制进度。
pDialog.setProgress(iCount++);
Thread.sleep(80);
}
pDialog.cancel();
} catch (InterruptedException e) { }
}
}.start(); }
}); m_btnCircle.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) { iCount = 0;
// 创建ProgressDialog对象
pDialog = new ProgressDialog(MainActivity.this); // 设置进度条风格,风格为圆形,旋转的
pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); // 设置ProgressDialog 标题
pDialog.setTitle("圆形进度条"); // 设置ProgressDialog 提示信息
pDialog.setMessage("正在下载中……"); // 设置ProgressDialog 标题图标
pDialog.setIcon(R.drawable.ic_launcher); // 设置ProgressDialog 进度条进度
pDialog.setProgress(100); // 设置ProgressDialog 的进度条是否不明确
pDialog.setIndeterminate(false); // 设置ProgressDialog 是否可以按退回按键取消
pDialog.setCancelable(true); // 设置ProgressDialog 的一个Button
pDialog.setButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int i) {
// 点击“取消”按钮取消对话框
dialog.cancel();
}
}); // 让ProgressDialog显示
pDialog.show(); // 创建线程实例
new Thread() {
public void run() {
try {
while (iCount <= 100) {
// 由线程来控制进度。
pDialog.setProgress(iCount++);
Thread.sleep(80);
}
pDialog.cancel();
} catch (InterruptedException e) {
pDialog.cancel();
}
} }.start(); }
});
} }

点击按钮效果:

    

10.Android之ProgressDialog进度对话框学习的更多相关文章

  1. (转载)Android自定义ProgressDialog进度等待框

    Android自定义ProgressDialog进度等待框 作者:无缘公子 字体:[增加 减小] 类型:转载 时间:2016-01-11我要评论 这篇文章主要介绍了Android自定义Progress ...

  2. 【转】24. android dialog ——ProgressDialog 进度条对话框详解

    原文网址:http://blog.csdn.net/jamesliulyc/article/details/6375598 首先在onCreateDialog方法里创建一个ProgressDialog ...

  3. 【转】【Android】ProgressDialog进度条对话框的使用

    Android ProgressDialog进度条对话框的使用: 转自:http://aina-hk55hk.iteye.com/blog/679134/ <?xml version=" ...

  4. android学习笔记20——ProgressDialog进度条对话框

    ProgressDialog==>进度条对话框 ProgressDialog本身就代表一个进度条对话框,程序只需要创建ProgressDialog实例,并将其显示出来就是一个进度条对话框:开发者 ...

  5. Android学习笔记(九)——更复杂的进度对话框

    显示操作进度的对话框 1.使用上一篇创建的同一项目.在activity_main.xml文件里加入一个Button: <Button android:id="@+id/btn_dial ...

  6. Android学习笔记(八)——显示运行进度对话框

    显示运行进度对话框 我们经常有这种经历:运行某一应用程序时.须要等待一会,这时会显示一个进度(Please Wait)对话框,让用户知道操作正在进行. 我们继续在上一篇中的程序中加入代码~ 1.在上一 ...

  7. Android开发系列(二十七):使用ProgressDialog创建进度对话框

    进度对话框在寻常的应用中非经常见,比方下载的时候,打开页面的时候.转移文件等等.有环形的.有长条形的. 基本就这两种 创建进度对话框的两种方式: 1.创建ProgressDialog实例,然后调用Pr ...

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

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

  9. 使用ProgressDialog创建进度对话框

    ProgressDialog代表了进度对话框,程序只要创建ProgressDialog实例,并将它显示出来就是一个进度对画框.使用ProgressDialog创建进度对话框有如下两种方式. ①如果只是 ...

随机推荐

  1. 2014 Super Training #7 F Power of Fibonacci --数学+逆元+快速幂

    原题:ZOJ 3774  http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3774 --------------------- ...

  2. nginx 一二事(2) - 创建虚拟静态服务器

    一.什么是nginx 是一个C语言开发的HTTP反向代理服务器,性能非常高 一个俄罗斯的哥们开发的,官方提供的测试性能能够达到5W的并发,我的天呐~,实际测试差不多是2W,而淘宝的牛人可以优化到200 ...

  3. 第23章 SEH结构化异常处理(3)_终止处理程序

    23.3 终止处理程序 23.3.1 程序的结构 (1)框架 __try{ //被保护的代码块 …… } __finally{ //终止处理 } (2)__try/__finally的特点 ①fina ...

  4. 转: java学习路线图

    http://www.java1234.com/javaxuexiluxiantu.html

  5. 斯坦福大学 iOS 7应用开发 ppt

    上网的找了很久都不全,最后发现原来网易那个视频下面就有完整的PPT..

  6. VideoView 播放资源目录raw下的视频

    你把影片copy到res/raw下!檔名小寫加底線,例如:default_video.3gp,在程式碼裡指定uri路徑 String uri = "android.resource://&q ...

  7. swift为UIView添加extension扩展frame

    添加swift file:UIView+Extension import UIKit extension UIView { // x var x : CGFloat { get { return fr ...

  8. 27Spring_的事务管理_银行转账业务加上事务控制_基于tx.aop进行声明式事务管理

    上一篇文章中,银行转账业务没有使用事务,会出现问题,所以这篇文章对上篇文章出现的问题进行修改. 事务 依赖 AOP , AOP需要定义切面, 切面由Advice(通知) 和 PointCut(切点) ...

  9. Linux 字符集转化

    命令行"iconv --list" 查看Linux操作系统支持的字符集 iconv_open 设置字符集转化 --iconv_t iconv_open(const char *to ...

  10. C#字符格式化占位符

    using System; using System.Diagnostics; using System.Text; using System.Collections; using System.Co ...