android 对话框中的进度条 (ProgressDialog)
from:http://byandby.iteye.com/blog/817214
显然要定义对话框进度条就要用ProgressDialog,首先我们需要创建ProgressDialog对象,当然这里同样使用了线程来控制进度条显示,另外可以使用以下方法来设置ProgressDialog。
setProgressStyle:设置进度条风格,风格为圆形,旋转的。
setTitlt:设置ProgressDialog 标题
setMessage:设置ProgressDialog提示信息;
setIcon:设置ProgressDialog标题图标;
setIndeterminate:设置ProgressDialog 的进度条是否不明确;
setCancelable:设置ProgressDialog 是否可以按返回键取消;
setButton:设置ProgressDialog 的一个Button(需要监听Button事件);
show:显示ProgressDialog。
首先还是让我们看看运行效果吧
下面先来看看布局文件
<?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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<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>
Activity01
- package xiaohang.zhimeng;
- 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 xhButton01, xhButton02;
- int xh_count = 0;
- // 声明进度条对话框
- ProgressDialog xh_pDialog;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- // 得到按钮对象
- xhButton01 = (Button) findViewById(R.id.Button01);
- xhButton02 = (Button) findViewById(R.id.Button02);
- // 设置xhButton01的事件监听
- xhButton01.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- // 创建ProgressDialog对象
- xh_pDialog = new ProgressDialog(Activity01.this);
- // 设置进度条风格,风格为圆形,旋转的
- xh_pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
- // 设置ProgressDialog 标题
- xh_pDialog.setTitle("提示");
- // 设置ProgressDialog提示信息
- xh_pDialog.setMessage("这是一个圆形进度条对话框");
- // 设置ProgressDialog标题图标
- xh_pDialog.setIcon(R.drawable.img1);
- // 设置ProgressDialog 的进度条是否不明确 false 就是不设置为不明确
- xh_pDialog.setIndeterminate(false);
- // 设置ProgressDialog 是否可以按退回键取消
- xh_pDialog.setCancelable(true);
- // 设置ProgressDialog 的一个Button
- xh_pDialog.setButton("确定", new Bt1DialogListener());
- // 让ProgressDialog显示
- xh_pDialog.show();
- }
- });
- // 设置xhButton02的事件监听
- xhButton02.setOnClickListener(new Button.OnClickListener() {
- @Override
- public void onClick(View v) {
- xh_count = 0;
- // 创建ProgressDialog对象
- xh_pDialog = new ProgressDialog(Activity01.this);
- // 设置进度条风格,风格为圆形,旋转的
- xh_pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
- // 设置ProgressDialog 标题
- xh_pDialog.setTitle("提示");
- // 设置ProgressDialog提示信息
- xh_pDialog.setMessage("这是一个长形进度条对话框");
- // 设置ProgressDialog标题图标
- xh_pDialog.setIcon(R.drawable.img2);
- // 设置ProgressDialog 的进度条是否不明确 false 就是不设置为不明确
- xh_pDialog.setIndeterminate(false);
- // 设置ProgressDialog 进度条进度
- xh_pDialog.setProgress(100);
- // 设置ProgressDialog 是否可以按退回键取消
- xh_pDialog.setCancelable(true);
- // 让ProgressDialog显示
- xh_pDialog.show();
- new Thread() {
- @Override
- public void run() {
- try {
- while (xh_count <= 100) {
- // 由线程来控制进度
- xh_pDialog.setProgress(xh_count++);
- Thread.sleep(100);
- }
- xh_pDialog.cancel();
- } catch (Exception e) {
- xh_pDialog.cancel();
- }
- }
- }.start();
- }
- });
- }
- // xhButton01的监听器类
- class Bt1DialogListener implements DialogInterface.OnClickListener {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- // 点击“确定”按钮取消对话框
- dialog.cancel();
- }
- }
- }
android 对话框中的进度条 (ProgressDialog)的更多相关文章
- C#.NET中使用BackgroundWorker在模态对话框中显示进度条
这里是一个示例,其中展示了如何使用Backgroundworker对象在模态对话框中显示后台操作的实时进度条. 首先是主窗体代码: using System; using System.Collect ...
- 关于JFace中的进度条对话框(ProgressMonitorDialog类)
在Windows操作系统中,最常用的进度条对话框就是文件复制时的弹出框,如果想让用户愉快的使用你开发 的软件,那么在执行某个较长时间的操作时候,就应该弹出一个进度条提示框,告诉用户程序正在做什么. 做 ...
- Android 中带有进度条效果的按钮(Button)
安卓中带有进度条效果的按钮,如下图: 1.布局文件如下activity_main.xml <RelativeLayout xmlns:android="http://schemas.a ...
- Android 使用ProgressBar实现进度条
ProgressBar简介ProgressBar是进度条组件,通常用于向用户展示某个耗时操作完成的进度,而不让用户感觉是程序失去了响应,从而更好地提升用户界面的友好型. 课程目标(1)制定Progre ...
- Android学习笔记- ProgressBar(进度条)
本节引言: 本节给大家带来的是Android基本UI控件中的ProgressBar(进度条),ProgressBar的应用场景很多,比如 用户登录时,后台在发请求,以及等待服务器返回信息,这个时候会用 ...
- Xamarin XAML语言教程Xamarin.Forms中构建进度条
Xamarin XAML语言教程Xamarin.Forms中构建进度条 ProgressBar被称为进度条,它类似于没有滑块的滑块控件.进度条总是水平放置的.本节将讲解如何使用进度条. 注意:进度条在 ...
- Android学习笔记(24):进度条组件ProgressBar及其子类
ProgressBar作为进度条组件使用,它还派生了SeekBar(拖动条)和RatingBar(星级评分条). ProgressBar支持的XML属性: Attribute Name Related ...
- 如何在UIAlertView中显示进度条
今天这个问题是,在一个iPhone程序中,我要在后台做大量的数据处理,希望在界面上显示一个进度条(Progress Bar)使得用户了解处理进度.这个进度条应该是在一个模态的窗口中,使界 今天这个问题 ...
- CListCtrl控件中显示进度条
CListCtrl控件的subitem中显示进度条 http://www.codeproject.com/Articles/6813/List-Control-Extended-for-Progres ...
随机推荐
- LINUX内核升级-更新网卡驱动
因项目需要,将当前内核(2.6.32-220.el6.x86_64)升级到目标内核(2.6.33-110.el6.x86_64),但是编译的目标 内核(2.6.33-110.el6.x86_64)的对 ...
- flask/sqlalchemy - OperationalError: (sqlite3.OperationalError) no such table
狗书第五章 记得要先创建表 执行 db.create_all()语句来创建表 https://segmentfault.com/q/1010000005794140
- 【Mac + Appium + Python3.6学习(二)】之Android自动化测试,appium-desktop配置和简易自动化测试脚本
上一篇文章介绍安装appium测试环境,这一片研究介绍如何测试Android自动化. 上一篇地址:<[Mac + Appium学习(一)]之安装Appium环境> 这一篇参考:<Ma ...
- 【转】Monkey测试6-Monkey Test Log
Moneky Test Log 分析: 首先用一个最简单的例子分析:monkey --pct-trackball 0 --throttle 100 -v 500/*p参数: 表示指定测试的程序/*v参 ...
- servelet 直接输出内容
package helloworld; import java.io.IOException; import javax.servlet.ServletException; import javax. ...
- 嵌入式开发之davinci--- 8148/8168/8127 中swms、Mosaic’s、display 显示pal 模式
(1) (2) (3) (4) -------------------------author:pkf ------------------------------time:2-3 --------- ...
- Python Numpy ValueError: data type must provide an itemsize
天朝网络锁国,百度找了半个小时找不出来原因,只能谷歌 谷歌第一条就是,顿时感觉幸福感来的太突然 原因是输入的矩阵均是字符串(从文件里读的) 那么就需要批量转数组,一行一行的转. 下面是我的代码: ro ...
- 用Flex实现常见的几种布局
用Flex实现常见的几种布局 1.水平,垂直居中. <style type="text/css"> .container{ display: flex; width: ...
- java httpSession 设置超时时间
1.设置过期时间方式一:在tomcat/conf/web.xml下加入一下内容 <session-config> <session-timeout>90</session ...
- 41个Web开发者必须收藏的JavaScript实用技巧
1. 将彻底屏蔽鼠标右键 oncontextmenu=”window.event.returnValue=false” < table border oncontextmenu=return(f ...