1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent"
  6. android:orientation="vertical" >
  7.  
  8. <Button
  9. android:id="@+id/progress"
  10. android:layout_width="wrap_content"
  11. android:layout_height="wrap_content"
  12. android:text="条形进度条" />
  13.  
  14. <Button
  15. android:id="@+id/circle"
  16. android:layout_width="wrap_content"
  17. android:layout_height="wrap_content"
  18. android:text="圆形进度条" />
  19.  
  20. </LinearLayout>
  1. package com.example.yanlei.my;
  2.  
  3. import android.app.ProgressDialog;
  4. import android.content.DialogInterface;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.view.Menu;
  8. import android.view.MenuItem;
  9. import java.util.Calendar;
  10. import android.app.Activity;
  11. import android.app.DatePickerDialog;
  12. import android.app.Dialog;
  13. import android.app.TimePickerDialog;
  14. import android.os.Bundle;
  15. import android.view.View;
  16. import android.widget.Button;
  17. import android.widget.DatePicker;
  18. import android.widget.EditText;
  19. import android.widget.TimePicker;
  20.  
  21. public class MainActivity extends AppCompatActivity {
  22.  
  23. //声明按钮
  24. private Button btnCircle=null;
  25. private Button btnProgress=null;
  26. //声明进度条对话框
  27. private ProgressDialog pdDialog=null;
  28. //进度计数
  29. int iCount = 0;
  30. @Override
  31. protected void onCreate(Bundle savedInstanceState) {
  32. super.onCreate(savedInstanceState);
  33. setContentView(R.layout.activity_main);
  34. btnCircle = (Button)findViewById(R.id.circle);
  35. btnProgress = (Button)findViewById(R.id.progress);
  36.  
  37. //设置btnCircle的事件监听
  38. btnCircle.setOnClickListener(new Button.OnClickListener() {
  39.  
  40. @Override
  41. public void onClick(View v){
  42.  
  43. iCount = 0;
  44. //创建ProgressDialog对象
  45. pdDialog = new ProgressDialog(MainActivity.this);
  46.  
  47. //设置进度条风格,风格为圆形,旋转的
  48. pdDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
  49.  
  50. // 设置ProgressDialog 标题
  51. pdDialog.setTitle("圆形进度条");
  52.  
  53. // 设置ProgressDialog 提示信息
  54. pdDialog.setMessage("正在下载中……");
  55.  
  56. // 设置ProgressDialog 标题图标
  57. pdDialog.setIcon(R.drawable.ic_launcher);
  58.  
  59. // 设置ProgressDialog 进度条进度
  60. pdDialog.setProgress(100);
  61.  
  62. // 设置ProgressDialog 的进度条是否不明确
  63. pdDialog.setIndeterminate(false);
  64.  
  65. // 设置ProgressDialog 是否可以按退回按键取消
  66. pdDialog.setCancelable(true);
  67.  
  68. // 设置ProgressDialog 的一个Button
  69. pdDialog.setButton("取消", new DialogInterface.OnClickListener() {
  70. public void onClick(DialogInterface dialog, int i)
  71. {
  72. //点击“取消”按钮取消对话框
  73. dialog.cancel();
  74. }
  75. });
  76.  
  77. // 让ProgressDialog显示
  78. pdDialog.show();
  79.  
  80. //创建线程实例
  81. new Thread(){
  82. public void run(){
  83. try{
  84. while (iCount <= 100) {
  85. // 由线程来控制进度。
  86. pdDialog.setProgress(iCount ++);
  87. Thread.sleep(50);
  88. }
  89. pdDialog.cancel();
  90. }
  91. catch (InterruptedException e){
  92. pdDialog.cancel();
  93. }
  94. }
  95.  
  96. }.start();
  97. }
  98.  
  99. });
  100.  
  101. //设置btnProgress的事件监听
  102. btnProgress.setOnClickListener(new Button.OnClickListener() {
  103. @Override
  104. public void onClick(View v)
  105. {
  106. iCount = 0;
  107. // 创建ProgressDialog对象
  108. pdDialog = new ProgressDialog(MainActivity.this);
  109.  
  110. // 设置进度条风格,风格为长形
  111. pdDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
  112.  
  113. // 设置ProgressDialog 标题
  114. pdDialog.setTitle("条形进度条");
  115.  
  116. // 设置ProgressDialog 提示信息
  117. pdDialog.setMessage("正在下载中……");
  118.  
  119. // 设置ProgressDialog 标题图标
  120. pdDialog.setIcon(R.drawable.ic_launcher);
  121.  
  122. // 设置ProgressDialog 进度条进度
  123. pdDialog.setProgress(100);
  124.  
  125. // 设置ProgressDialog 的进度条是否不明确
  126. pdDialog.setIndeterminate(false);
  127.  
  128. // 设置ProgressDialog 是否可以按退回按键取消
  129. pdDialog.setCancelable(true);
  130.  
  131. // 让ProgressDialog显示
  132. pdDialog.show();
  133.  
  134. //创建线程实例
  135. new Thread(){
  136. public void run(){
  137. try{
  138. while (iCount <= 100) {
  139. // 由线程来控制进度。
  140. pdDialog.setProgress(iCount ++);
  141. Thread.sleep(50);
  142. }
  143. pdDialog.cancel();
  144. }
  145. catch (InterruptedException e){
  146. pdDialog.cancel();
  147. }
  148. }
  149.  
  150. }.start();
  151. }
  152. });
  153. }
  154.  
  155. @Override
  156. public boolean onCreateOptionsMenu(Menu menu) {
  157. // Inflate the menu; this adds items to the action bar if it is present.
  158. getMenuInflater().inflate(R.menu.menu_main, menu);
  159. return true;
  160. }
  161.  
  162. @Override
  163. public boolean onOptionsItemSelected(MenuItem item) {
  164. // Handle action bar item clicks here. The action bar will
  165. // automatically handle clicks on the Home/Up button, so long
  166. // as you specify a parent activity in AndroidManifest.xml.
  167. int id = item.getItemId();
  168.  
  169. //noinspection SimplifiableIfStatement
  170. if (id == R.id.action_settings) {
  171. return true;
  172. }
  173.  
  174. return super.onOptionsItemSelected(item);
  175. }
  176. }

Android 进度条对话框ProgressDialog的更多相关文章

  1. android学习笔记20——ProgressDialog进度条对话框

    ProgressDialog==>进度条对话框 ProgressDialog本身就代表一个进度条对话框,程序只需要创建ProgressDialog实例,并将其显示出来就是一个进度条对话框:开发者 ...

  2. Android——ProgressDialog 进度条对话框

    public class ProgressDialogActivity extends Activity {    private Button btn_large_pd, btn_horizonta ...

  3. Android开发 ---构建对话框Builder对象,消息提示框、列表对话框、单选提示框、多选提示框、日期/时间对话框、进度条对话框、自定义对话框、投影

    效果图: 1.activity_main.xml 描述: a.定义了一个消息提示框按钮 点击按钮弹出消息 b.定义了一个选择城市的输入框 点击按钮选择城市 c.定义了一个单选提示框按钮 点击按钮选择某 ...

  4. Android Studio常见对话框(普通对话框、单选对话框、多选对话框、进度条对话框、消息对话框、自定义对话框)

    Android Studio常见对话框(普通对话框.单选对话框.多选对话框.进度条对话框.消息对话框.自定义对话框) 1.普通对话框 2.单选对话框 3.多选对话框 4.进度条对话框 5.消息对话框 ...

  5. 【转】24. android dialog ——ProgressDialog 进度条对话框详解

    原文网址:http://blog.csdn.net/jamesliulyc/article/details/6375598 首先在onCreateDialog方法里创建一个ProgressDialog ...

  6. 【转】【Android】ProgressDialog进度条对话框的使用

    Android ProgressDialog进度条对话框的使用: 转自:http://aina-hk55hk.iteye.com/blog/679134/ <?xml version=" ...

  7. ProgressDialog进度条对话框

    (一) 1.效果图: 2.activity_main.xml <?xml version="1.0" encoding="utf-8"?> < ...

  8. ProgressWheelDialogUtil【ProgressWheel Material样式进度条对话框】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 简单封装网络请求时的加载对话框以及上传.下载文件的进度加载对话框. 效果图 代码分析 ProgressWheel : 自定义view ...

  9. AlertDialog之常见对话框(单选对话框、多选对话框、进度条对话框)

    单选对话框,顾名思义就是只能选一项(setSingleChoiceItems(Items,)) public void click(View v){ //创建对话框类 AlertDialog.Buil ...

随机推荐

  1. ASP.NET下调用ffmpeg与mencoder实现视频转换截屏

    最近要做一个视频播放的系统,用到了ffmpeg和mencoder两个工具,查了一些资料,发现这方面的资料还挺多的,但是就是乱了一点,我自己从头整理了一下,和大家分享一下: 1.ffmpeg实现视频(a ...

  2. 46、android studio第一次使用时卡在gradle下载怎么解决?

    如果没法FQ或者FQ后网速慢,哥教你一个快速解决方案. 在根目录下的.gradle目录下,找到wrapper/dists目录,如果当前正在下载gradle.x.xx-all.zip,那么会发现grad ...

  3. Python+Selenium练习篇之20-处理Alert弹窗

    本文来介绍如何通过Selenium方法去处理网页Alert弹窗,和处理iframe类似,都是通过switch_to方法.这里还是没有找到合适的alert弹窗网站,我们就自己创建一个吧,前面文章介绍了如 ...

  4. 微信小程序-----校园头条详细开发之首页

    1.首页展示功能的实现 1.1  结构 1.2 代码实现 1.2.1  界面的设计这里就不多说了,样式都是我自己写的,还有就是页面的跳转,看详细代码 var app = getApp() Page({ ...

  5. nyoj 题目7 街区最短路径问题

    街区最短路径问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 一个街区有很多住户,街区的街道只能为东西.南北两种方向. 住户只可以沿着街道行走. 各个街道之间的间 ...

  6. 【转】unity自带寻路Navmesh入门教程(二)

    http://liweizhaolili.blog.163.com/blog/static/16230744201271210237616/ 上一节简单介绍了NavMesh寻路的基本用法,这次来介绍一 ...

  7. Log4j官方文档翻译(一、基本介绍)

    简介 log4j是使用java语言编写的可靠的.快速的.灵活的日志框架,它是基于Apache的license. log4j支持c,c++,c#,perl,python,ruby等语言.在运行时通过额外 ...

  8. codevs 1690 开关灯 线段树区间更新 区间查询Lazy

    题目描述 Description YYX家门前的街上有N(2<=N<=100000)盏路灯,在晚上六点之前,这些路灯全是关着的,六点之后,会有M(2<=m<=100000)个人 ...

  9. git repo gerrit 的关系

    Git作为一个版本控制工具,功能很强大,新建分支,切换分支都很快,小团队用Git就能很好地管理好了,但如果是Android系统如此庞大的工程呢,我们知道全套Android源码是很大很大的,目录结构也很 ...

  10. 对计算属性中get和set的理解

    原文参考:https://blog.csdn.net/xiaxiaoxian/article/details/79304004