3.4 复杂进度对话框
2016-02-03 07:36
281 查看
这一小节我们来给大家讲讲复杂进度对话框的用法,先看截图吧
大家一看就知道是一个带有下载进度的对话框,那么了解这个对话框常用用法如下
初始化进度条
设置图标、标题
设置进度条风格
设置进度条起始值
设置进度条每次增长值
这里我们就把ProgressDialog常用的代码方法也列举出来供大家参考
setIcon ,设置进度对话框的图标
setProgress, 设置进度对话框的起始值
setTitle, 设置进度对话框的标题
setProgressStyle, 设置进度对话框的样式
show, 显示对话框
incrementProgressBy,设置进度对话框的增长值
setIndeterminate, 不显示进度值
setMessage, 设置进度对话框中下载内容信息
OnCancelListener,监听进度对话框取消事件
OnDismissListener,监听进度对话框消失事件
下面就是代码的具体实现
文字内容来自:国信安刘阳
大家一看就知道是一个带有下载进度的对话框,那么了解这个对话框常用用法如下
初始化进度条
设置图标、标题
设置进度条风格
设置进度条起始值
设置进度条每次增长值
这里我们就把ProgressDialog常用的代码方法也列举出来供大家参考
setIcon ,设置进度对话框的图标
setProgress, 设置进度对话框的起始值
setTitle, 设置进度对话框的标题
setProgressStyle, 设置进度对话框的样式
show, 显示对话框
incrementProgressBy,设置进度对话框的增长值
setIndeterminate, 不显示进度值
setMessage, 设置进度对话框中下载内容信息
OnCancelListener,监听进度对话框取消事件
OnDismissListener,监听进度对话框消失事件
下面就是代码的具体实现
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/hello_world" android:onClick="show"></Button> </RelativeLayout>
package com.gxa; import android.os.Bundle; import android.app.Activity; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.DialogInterface.OnCancelListener; import android.content.DialogInterface.OnDismissListener; import android.view.Menu; import android.view.View; import android.widget.Toast; public class MainActivity extends Activity implements OnCancelListener, OnDismissListener { private ProgressDialog dialog; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } public void show(View view) { onCreateProgressDialog(); dialog.setOnCancelListener(this); dialog.setOnDismissListener(this); } public void onCreateProgressDialog() { dialog = new ProgressDialog(this); dialog.setIcon(R.drawable.ic_launcher); dialog.setTitle("下载..."); dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); dialog.setProgress(0); dialog.show(); new Thread(new Runnable() { @Override public void run() { for (int i = 0; i < 25; i++) { try { Thread.sleep(1000); dialog.incrementProgressBy((int) 100 / 25); } catch (InterruptedException e) { dialog.cancel(); } } dialog.dismiss(); } }).start(); } @Override public void onCancel(DialogInterface dialog) { Toast.makeText(this, "下载取消", Toast.LENGTH_SHORT).show(); } @Override public void onDismiss(DialogInterface dialog) { Toast.makeText(this, "下载完成", Toast.LENGTH_SHORT).show(); } }
文字内容来自:国信安刘阳
相关文章推荐
- 关于ObjectOutputStream
- SpatialHdoop中空间索引的构建
- 如何利用支付宝集福(敬业福)引流
- MatLab 组件大全
- Android实现网络多线程断点续传下载
- ActiveMQ集群(2)
- 滴滴5亿年终奖,根据这四个问题来发
- 解决Win10服务主机本地系统网络受限
- Leetcode - 295. Find Median From Data Stream
- [LeetCode]161. One Edit Distance
- 12 类别与扩展
- 软件开发管理: 技术午餐会(brown bag)
- maya中的桥接命令
- ionic build --release android
- redis
- LeetCode "Verify Preorder Serialization of a Binary Tree"
- spring ioc,aop工作原理
- The problem of extent not match in ArcMap.
- Java 常用排序算法/程序员必须掌握的 8大排序算法
- SQL优化----百万数据查询优化