Android 之 ProgressDialog用法介绍
布局文件测试:
<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用法介绍的更多相关文章
- 怎么通过activity里面的一个按钮跳转到另一个fragment(android FragmentTransaction.replace的用法介绍)
即:android FragmentTransaction.replace的用法介绍 Fragment的生命周期和它的宿主Activity密切相关,几乎和宿主Activity的生命周期一致,他们之间最 ...
- Android中的AlertDialog和ProgressDialog用法
手机APP对话框是很多APP都有的下面来看下怎么实现的吧, 打开Android studio 然他自动创建好布局和类; 下面我们修改activity_main.xml中的代码 <?xml ver ...
- Android之Adapter用法总结-(转)
Android之Adapter用法总结 1.概念 Adapter是连接后端数据和前端显示的适配器接口,是数据和UI(View)之间一个重要的纽带.在常见的View(List View,Grid Vie ...
- Android之Adapter用法总结(转)
Android之Adapter用法总结 1.概念 Adapter是连接后端数据和前端显示的适配器接口,是数据和UI(View)之间一个重要的纽带.在常见的View(List View,Grid Vie ...
- Android中ProgressDialog的简单示例
网上一般对进度条的示例都是如何显示,没有在任务结束如何关闭的文章,参考其他文章经过试验之后把整套进度条显示的简单示例如下: 建立android工程等工作都略去,Google一下就可以了. 下面来介绍主 ...
- Android之Adapter用法总结
http://blog.csdn.net/fznpcy/article/details/8658155 Android之Adapter用法总结 1.概念 Adapter是连接后端数据和前端显示的适配器 ...
- Android官方架构组件介绍之LifeCycle(一)
Android官方架构组件介绍之LifeCycle 下面是官方提供的Android App开发的架构图: 从上图可以看到一些关键字:ViewModel,LiveData,Room等.其实看了上面视频的 ...
- (转载)Android自定义ProgressDialog进度等待框
Android自定义ProgressDialog进度等待框 作者:无缘公子 字体:[增加 减小] 类型:转载 时间:2016-01-11我要评论 这篇文章主要介绍了Android自定义Progress ...
- 好压(HaoZip)的命令行模式用法介绍
好压压缩软件,又叫“2345好压”,是一款国产的优秀压缩软件,目前是免费的,据官网介绍,该软件永久免费.官网地址:http://haozip.2345.com/ 本文主要对该软件的命令行模式用法进行介 ...
随机推荐
- Python Turtle
之前对这个turtle这个模块不了解,觉得没什么意思,最近试了一下发现不错,来点最简单的.写的时候深刻感受到自己智商是个硬伤,算角度都算了半天... 图就不导了吧,懒癌晚期... import tur ...
- 如何使CEF支持Flash
方法一:复制Chrome浏览器下的pepperFlash,通过cef命令行参数设置路径. public Form1() { InitializeComponent(); InitializeChrom ...
- C# 对多个文件进行zip压缩
本文使用的ICSharpCode.SharpZipLib.dll类库来实现文件压缩,你可以通过Nuget来安装此类库,或者到搜索引擎去搜索一下遍地都是.类库下载下来之后,添加到项目引用就可以了.下面这 ...
- How to make your assembly more secure from referencing by unauthorized bits
Now the security has a trend to become more and more important in our daily work, hence I did some r ...
- jmobile学习之路 ---- 视口
当我们的浏览器在窗口最大化的时候,此时屏幕的宽度,就是我们桌面的分辨率.这个规则仅仅适用于PC! 我们试图在iPhone中输出屏幕宽度,你会发现屏幕宽度是980!居然和PC屏幕差不多大! 苹果主导的这 ...
- SPRING SECURITY JAVA配置:Web Security
在前一篇,我已经介绍了Spring Security Java配置,也概括的介绍了一下这个项目方方面面.在这篇文章中,我们来看一看一个简单的基于web security配置的例子.之后我们再来作更多的 ...
- PHP:Xdebug配置
在配置Xdebug时,之前经历了无数次失败,终于配置成功! 以下是配置失败的原因: 1.下载时,选用Xdebug的版本不正确: 2.配置时,Xdebug文件名或文件的路径不正确: 在参考 http:/ ...
- centos 6.5 升级内核 linux 3.12.17 (笔记 实测)
环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G) 系统版本:Linux centos 2.6.32-431.el6.x86_64(Centos-6.5-x86_64-mi ...
- CF2.C(二分贪心)
C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- PHP之几道面试题
1.二分查找算法 function two_find($arr,$low,$height,$k){ if($low<=$height){ $mid = intval(($low+$height) ...