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. Android Studio系列教程一--下载和安装

    原文链接:http://stormzhang.com/devtools/2014/11/25/android-studio-tutorial1/ 背景 相信大家对Android Studio已经不陌生 ...

  2. 后台首页品字形(frameset)框架搭建

    get_defined_constants([true])//显示所有常量信息.参数true,表示分组显示,查看当前系统给我提供了哪些常量可以使用,包括自定义常量. __CONTROLLER__//获 ...

  3. 分布式监控系统Zabbix-3.0.3-完整安装记录(4)-解决zabbix监控图中出现中文乱码问题

    之前部署了Zabbix-3.0.3监控系统,在安装数据库时已经将zabbix库设置了utf-8字符. 首先确定zabbix开启了中文支持功能:登录到zabbix服务器的数据目录下(前面部署的zabbi ...

  4. iOS原生地图开发进阶——使用导航和附近兴趣点检索

    iOS原生地图开发进阶——使用导航和附近兴趣点检索 iOS中的mapKit框架对国际化的支持非常出色.在前些篇博客中,对这个地图框架的基础用法和标注与覆盖物的添加进行了详细的介绍,这篇博客将介绍两个更 ...

  5. WPF Extended WPF Toolkit

    1.VS 2013 通过NUGet获取Extended WPF Toolkit 我自己的项目已安装 2.在自己页面引用Extended WPF Toolkit xmlns:xctk="htt ...

  6. 012医疗项目-模块一:统一异常处理器的设计思路及其实现(涉及到了Springmvc的异常处理流程)

    我们上一篇文章是建立了一个自定义的异常类,来代替了原始的Exception类.在Serice层抛出异常,然后要在Action层捕获这个异常,这样的话在每个Action中都要有try{}catch{}代 ...

  7. 15Mybatis_输出类型

    输出类型分为两种:1.resultType          和         2.resultMap 接下来先讲解resultType: 使用resultType进行输出映射,只有查询出来的列名和 ...

  8. ASP.NET错误处理的方式(总结)

    转载至: http://www.cnblogs.com/chinhr/archive/2007/06/26/795947.html ASP.NET错误处理的方式(整理&总结)英文文章研究:ht ...

  9. LUA GC 简单测试

    function table.count(t) if type(t) ~= "table" then assert(false) return end for k, _ in pa ...

  10. no.1

    #import requests import urllib import bs4 try: html=urllib.urlopen('http://anyun.org') except HTTPer ...