布局文件测试:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
> <Button
android:id="@+id/cricle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="圆形进度条测试" /> <Button
android:id="@+id/rec"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="长形进度条测试" /> </LinearLayout>

  测试代码入口:

package com.example.progressdialog;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button; public class MainActivity extends Activity { private Button circle;
private Button rec;
private ProgressDialog myDialog;
int count = ;// 存储进度条当前值,初始为 0
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); // 获取对象
circle = (Button) findViewById(R.id.cricle);
rec = (Button) findViewById(R.id.rec); // 圆形按钮测试
circle.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { circle();
}
}); // 矩形进度条测试
rec.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
rec();
}
}); } /**
* 圆形进度条测试..
*/
public void circle() {
myDialog = new ProgressDialog(MainActivity.this); // 获取对象
myDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); // 设置样式为圆形样式
myDialog.setTitle("友情提示"); // 设置进度条的标题信息
myDialog.setMessage("数据加载中,请稍后..."); // 设置进度条的提示信息
myDialog.setIcon(R.drawable.ic_launcher); // 设置进度条的图标
myDialog.setIndeterminate(false); // 设置进度条是否为不明确
myDialog.setCancelable(true); // 设置进度条是否按返回键取消 // 为进度条添加确定按钮 , 并添加单机事件
myDialog.setButton("确定", new OnClickListener() { public void onClick(DialogInterface dialog, int which) { myDialog.cancel(); // 撤销进度条
}
}); myDialog.show(); // 显示进度条
} /**
* 矩形进度条测试...
*/
public void rec() { myDialog = new ProgressDialog(MainActivity.this); // 得到一个对象
myDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); // 设置为矩形进度条
myDialog.setTitle("提示");
myDialog.setMessage("数据加载中,请稍后...");
myDialog.setIcon(R.drawable.ic_launcher);
myDialog.setIndeterminate(false); // 设置进度条是否为不明确
myDialog.setCancelable(true);
myDialog.setMax(); // 设置进度条的最大值
myDialog.setProgress(); // 设置当前默认进度为 0
myDialog.setSecondaryProgress(); // 设置第二条进度值为100 // 为进度条添加取消按钮
myDialog.setButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
myDialog.cancel();
}
}); myDialog.show(); // 显示进度条
new Thread() {
public void run() {
while (count <= ) {
myDialog.setProgress(count++);
try {
Thread.sleep(); //暂停 0.1秒
} catch (Exception e) {
Log.i("msg","线程异常..");
}
}
}
}.start(); } }

  demo下载地址:http://pan.baidu.com/s/1gddHDh5

Android 之 ProgressDialog用法介绍的更多相关文章

  1. 怎么通过activity里面的一个按钮跳转到另一个fragment(android FragmentTransaction.replace的用法介绍)

    即:android FragmentTransaction.replace的用法介绍 Fragment的生命周期和它的宿主Activity密切相关,几乎和宿主Activity的生命周期一致,他们之间最 ...

  2. Android中的AlertDialog和ProgressDialog用法

    手机APP对话框是很多APP都有的下面来看下怎么实现的吧, 打开Android studio 然他自动创建好布局和类; 下面我们修改activity_main.xml中的代码 <?xml ver ...

  3. Android之Adapter用法总结-(转)

    Android之Adapter用法总结 1.概念 Adapter是连接后端数据和前端显示的适配器接口,是数据和UI(View)之间一个重要的纽带.在常见的View(List View,Grid Vie ...

  4. Android之Adapter用法总结(转)

    Android之Adapter用法总结 1.概念 Adapter是连接后端数据和前端显示的适配器接口,是数据和UI(View)之间一个重要的纽带.在常见的View(List View,Grid Vie ...

  5. Android中ProgressDialog的简单示例

    网上一般对进度条的示例都是如何显示,没有在任务结束如何关闭的文章,参考其他文章经过试验之后把整套进度条显示的简单示例如下: 建立android工程等工作都略去,Google一下就可以了. 下面来介绍主 ...

  6. Android之Adapter用法总结

    http://blog.csdn.net/fznpcy/article/details/8658155 Android之Adapter用法总结 1.概念 Adapter是连接后端数据和前端显示的适配器 ...

  7. Android官方架构组件介绍之LifeCycle(一)

    Android官方架构组件介绍之LifeCycle 下面是官方提供的Android App开发的架构图: 从上图可以看到一些关键字:ViewModel,LiveData,Room等.其实看了上面视频的 ...

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

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

  9. 好压(HaoZip)的命令行模式用法介绍

    好压压缩软件,又叫“2345好压”,是一款国产的优秀压缩软件,目前是免费的,据官网介绍,该软件永久免费.官网地址:http://haozip.2345.com/ 本文主要对该软件的命令行模式用法进行介 ...

随机推荐

  1. ajax和jquery

    ajax的定义: AJAX即“Asynchronous Javascript And XML”(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术. AJAX = 异步 Ja ...

  2. js获取HTTP的请求头信息

    以下为js获取HTTP的全部请求头信息: var req = new XMLHttpRequest(); req.open('GET', document.location, false); req. ...

  3. poj3629

    //(队列)poj3629 /* #include <iostream> #include <queue> #include <algorithm> using n ...

  4. asp.net实现数据库版动态网页滑动门

    前端: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="滑动门.aspx.c ...

  5. Mysql 表分区

    是否支持分区:mysql> show variables like '%partition%';+-----------------------+-------+| Variable_name ...

  6. dfs判断连通图(无向)

    在图论中,连通图基于连通的概念.在一个无向图 G 中,若从顶点vi到顶点vj有路径相连(当然从vj到vi也一定有路径),则称vi和vj是连通的.如果 G 是有向图,那么连接vi和vj的路径中所有的边都 ...

  7. bzoj3380+3381+3382+3383 Usaco2004 Open

    四道比较水的题 T1:SPFA+状压 #include<stdio.h> #include<string.h> #include<algorithm> #inclu ...

  8. linux 用户管理(一)

    本节内容梗概: 1.用户管理配置文件 2.用户管理命令 3.用户组管理命令 4.批量添加用户 5.用户授权 学东西先讲原理,所以从配置文件入手 1.用户信息文件  /etc/passwd 存放了用户的 ...

  9. RSA密钥生成与使用

    RSA密钥生成与使用 openssl生成工具链接:http://pan.baidu.com/s/1c0v3UxE 密码:uv48 1. 打开openssl密钥生成软件打开 openssl 文件夹下的  ...

  10. C#多线程介绍(下)

    转载原文:这里是链接内容 转载原文:这里写链接内容 转载原文:这里写链接内容 (重要事情说三遍) 引言 本文主要从线程的基础用法,CLR线程池当中工作者线程与I/O线程的开发,并行操作PLINQ等多个 ...