【转】Android ProgressDialog的使用
原文网址: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>范例


- package com.yarin.android.Examples_04_24;
- import android.app.Activity;
- import android.app.ProgressDialog;
- import android.content.DialogInterface;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- public class Activity01 extends Activity
- {
- private Button Button1 = null;
- private Button Button2 = null;
- int count = 0;
- //声明进度条对话框
- ProgressDialog progressDialog = null;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- //得到按钮对象
- Button1 = (Button)findViewById(R.id.Button01);
- Button2 = (Button)findViewById(R.id.Button02);
- //设置mButton01的事件监听
- Button1.setOnClickListener(new Button1Listener());
- //设置mButton02的事件监听
- Button2.setOnClickListener(new Button2Listener());
- }
- private class Button1Listener implements OnClickListener{
- public void onClick(View v) {
- //创建ProgressDialog对象
- progressDialog = new ProgressDialog(Activity01.this);
- // 设置进度条风格,风格为圆形,旋转的
- progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
- // 设置ProgressDialog 标题
- progressDialog.setTitle("提示");
- // 设置ProgressDialog 提示信息
- progressDialog.setMessage("这是一个圆形进度条对话框");
- // 设置ProgressDialog 标题图标
- progressDialog.setIcon(R.drawable.a);
- // 设置ProgressDialog 的进度条是否不明确
- progressDialog.setIndeterminate(false);
- // 设置ProgressDialog 是否可以按退回按键取消
- progressDialog.setCancelable(true);
- //设置ProgressDialog 的一个Button
- progressDialog.setButton("确定", new SureButtonListener());
- // 让ProgressDialog显示
- progressDialog.show();
- }
- }
- //Dialog中确定按钮的监听器
- private class SureButtonListener implements android.content.DialogInterface.OnClickListener{
- public void onClick(DialogInterface dialog, int which) {
- //点击“确定按钮”取消对话框
- dialog.cancel();
- }
- }
- private class Button2Listener implements OnClickListener{
- public void onClick(View v) {
- count = 0;
- // 创建ProgressDialog对象
- progressDialog = new ProgressDialog(Activity01.this);
- // 设置进度条风格,风格为长形
- progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
- // 设置ProgressDialog 标题
- progressDialog.setTitle("提示");
- // 设置ProgressDialog 提示信息
- progressDialog.setMessage("这是一个长形对话框进度条");
- // 设置ProgressDialog 标题图标
- progressDialog.setIcon(R.drawable.a);
- // 设置ProgressDialog 进度条进度
- progressDialog.setProgress(100); 《==应该改为 progressDialog.setMax(100)
- // 设置ProgressDialog 的进度条是否不明确
- progressDialog.setIndeterminate(false);
- // 设置ProgressDialog 是否可以按退回按键取消
- progressDialog.setCancelable(true);
- // 让ProgressDialog显示
- progressDialog.show();
- new Thread()
- {
- public void run()
- {
- try
- {
- while (count <= 100)
- {
- // 由线程来控制进度。
- progressDialog.setProgress(count++);
- Thread.sleep(100);
- }
- progressDialog.cancel();
- }
- catch (InterruptedException e)
- {
- progressDialog.cancel();
- }
- }
- }.start();
- }
- }
- }
- <?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"
- >
- <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>
【转】Android ProgressDialog的使用的更多相关文章
- 【转】Android ProgressDialog的使用2
原文网址:http://www.cnblogs.com/hnrainll/archive/2012/03/28/2420908.html <?xml version="1.0" ...
- Android ProgressDialog 加载进度
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools= ...
- android progressdialog 对话框试用实例
ProgressDialog 跟AlertDialog用法差不多,不同的是:ProgressDialog 显示的是一种"加载中"的效果,android 中 ProgressDial ...
- android ProgressDialog 正在载...Loading...
final ProgressDialog pd = new ProgressDialog(mContext); pd.setMessage("正在加载..."); pd.show( ...
- Android——ProgressDialog 进度条对话框
public class ProgressDialogActivity extends Activity { private Button btn_large_pd, btn_horizonta ...
- Android ProgressDialog 简单实用
ProgressDialog progressDialog; @SuppressLint("HandlerLeak") Handler handler1 = new Handler ...
- android:ProgressDialog控件
ProgressDialog 和 AlertDialog 有点类似,都可以在界面上弹出一个对话框,都能够屏蔽 掉其他控件的交互能力.不同的是,ProgressDialog 会在对话框中显示一个进度条, ...
- 自定义android ProgressDialog
Android系统自己提供的UI的都是比较难看的,开发中经常用到自定义对话框,下面分享个最近项目中使用的加载框. 下面是源代码,主要的原理就是准备几个图片,然后循环播放. MainActivity ...
- Android学习笔记_81_Android ProgressDialog ProgressBar 各种效果
1,弹出Dialog 屏幕不变暗. 创建一个样式就OK了:在styles.xml文件里添加样式: 1, <style name="dialog" parent="@ ...
随机推荐
- SAMBA用户访问指定的目录
指定某个用户访问一个特定的共享文件夹sfx 用户可以访问abc目录 别的用户不可以访问abc目录 先创建一个用户命令useradd sfx 创建一个smbpasswd用户 在创建这个用户时要先创建一个 ...
- JAVA时间日期处理类,主要用来遍历两个日期之间的每一天。
/** * * 文 件 名: AccountDate.java * * 创建时间: 2008-11-18 * * Email : **@163.com */ import java.text.Deci ...
- UITableView编写可以添加,删除,移动的物品栏(二)
MyTableViewCell.h文件(自定义ViewCell)的内容: MyTableViewCell.m的内容
- JS常用的7中跨域方式总结
javascript跨域有两种情况: 1.基于同一父域的子域之间,如:a.c.com和b.c.com 2.基于不同的父域之间,如:www.a.com和www.b.com 3.端口的不同,如:ww ...
- 使用 fn 标签 解决字数过多时用省略号代替 .............................
list列表单条记录某字段大于10就后面添加省略号(如:内容只是显示开始的10个字,后面的用省略号代替) 在list列表中单条记录某字段大于10就后面添加省略号, 首先引入 jstl标签: <% ...
- php5.4安装ecshopphp5.4问题及解决
includes/cls_template.php line422 将 $tag_sel = array_shift(explode(" ", $tag)); 这句话拆开为两句. $tag_exp = ...
- web常用正则表达式
1. 平时做网站经常要用正则表达式,下面是一些讲解和例子,仅供大家参考和修改使用: 2. "^\d+$" //非负整数(正整数 + 0) 3. "^[0-9]*[1-9] ...
- 快速搭建高速稳定三层B/S架构
- net Core 通过 Ef Core 访问、管理Mysql
net Core 通过 Ef Core 访问.管理Mysql 本文地址:http://www.cnblogs.com/likeli/p/5910524.html 环境 dotnet Core版本:1. ...
- vim设置
折腾一下vim http://www.cnblogs.com/zhangsf/archive/2013/06/13/3134409.html