public class MainActivity extends Activity implements View.OnClickListener{
private ProgressBar progress;
private Button add;
private Button reduce;
private Button reset;
private Button show;
private TextView text;
private ProgressDialog prodig; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //注册控件
init(); add.setOnClickListener(this);
reduce.setOnClickListener(this);
reset.setOnClickListener(this);
show.setOnClickListener(this);
} private void init() {
progress = (ProgressBar)findViewById(R.id.progressBar);
add = (Button) findViewById(R.id.button1);
reduce = (Button) findViewById(R.id.button2);
reset =(Button)findViewById(R.id.button3);
text =(TextView)findViewById(R.id.textView);
show =(Button)findViewById(R.id.show); //获取进度
int first = progress.getProgress();
int second= progress.getSecondaryProgress();
int Max = progress.getMax(); text.setText("第一进度条百分比:" + ((int) (first / (float) Max * 100)) + "第二进度条百分比为:" + ((int) (second / (float) Max * 100)));
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.button1:
progress.incrementProgressBy(10);
progress.incrementSecondaryProgressBy(10);
break;
case R.id.button2:
progress.incrementProgressBy(-10);
progress.incrementSecondaryProgressBy(-10);
break;
case R.id.button3:
progress.setProgress(0);
progress.setSecondaryProgress(10);
break;
case R.id.show:
//新建ProgressDialog对象
prodig = new ProgressDialog(MainActivity.this); //设置ProgressDialog显示风格
prodig.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); //设置ProgressDialog标题
prodig.setTitle("慕尼黑"); //设置ProgressDialog文本信息
prodig.setMessage("欢迎大家支持慕课网!"); //设置ProgressDialog图标
prodig.setIcon(R.mipmap.ic_launcher); /*
设置ProgressBar进度条属性
*/
//设定最大进度条
prodig.setMax(100); //设定初始化进度
prodig.incrementProgressBy(50); //进度条明确显示进度 设置为ture就会来回滚动 表示在运行
prodig.setIndeterminate(false); /*
设定一个确定按钮
*/
prodig.setButton(DialogInterface.BUTTON_POSITIVE,"确定可好?", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this,"今天天气萌萌哒",Toast.LENGTH_SHORT).show();
}
}); //点击ProgressDialog区域来退出
prodig.setCancelable(true); //显示ProgressDialog
prodig.show();
break;
}
text.setText("第一进度条百分比:" + ((int) (progress.getProgress() / (float) progress.getMax() * 100)) + "第二进度条百分比为:" + ((int) (progress.getSecondaryProgress() / (float) progress.getMax() * 100)));
}

  注意:

1.进度条明确显示进度 设置为ture就会来回滚动 表示在运行

prodig.setIndeterminate(false);
prodig.incrementProgressBy(50);

2.ProgressDialog进度条 设置初始值时

在show()之前 只能用

prodig.incrementProgressBy(50);
show()之后
才能用prodig.setProgress(50); activity_main.xml
<LinearLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:orientation="vertical"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <ProgressBar
android:secondaryProgress="100"
android:progress="50"
android:max="100"
style="@android:style/Widget.ProgressBar.Horizontal"
android:progressDrawable="@drawable/asd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/progressBar" /> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/plus"
android:id="@+id/button1" /> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/minus"
android:id="@+id/button2" /> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/reset"
android:id="@+id/button3" /> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/show"
android:id="@+id/show" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView" /> </LinearLayout>

  

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】ProgressDialog进度条对话框的使用

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

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

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

  5. ProgressDialog进度条对话框

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

  6. android 对话框中的进度条 (ProgressDialog)

    from:http://byandby.iteye.com/blog/817214 显然要定义对话框进度条就要用ProgressDialog,首先我们需要创建ProgressDialog对象,当然这里 ...

  7. Android 进度条对话框ProgressDialog

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  8. 10.Android之ProgressDialog进度对话框学习

    APP应用中经常会下载某些东西,这里面有涉及到进度对话框,今天来学习下. 首先,布局里放进两个按钮,点击一个显示条形进度条,另一个显示圆形进度条.代码如下: <?xml version=&quo ...

  9. (转载)Android自定义ProgressDialog进度等待框

    Android自定义ProgressDialog进度等待框 作者:无缘公子 字体:[增加 减小] 类型:转载 时间:2016-01-11我要评论 这篇文章主要介绍了Android自定义Progress ...

随机推荐

  1. 完整搭建一个vue项目

    目录 一. 搭建一个vue项目的完整步骤 二. 卸载vue-cli 三. 完全卸载webpack 一. 搭建一个vue项目的完整步骤 1.安装node.js 下载地址 # 检查是否安装成功 node ...

  2. [SOME_MUTATION] (state) {// mutate state}Vuex中使用 ES2015 风格的计算属性命名功能来使用一个常量作为函数名

    使用常量替代 Mutation 事件类型 使用常量替代 mutation 事件类型在各种 Flux 实现中是很常见的模式.这样可以使 linter 之类的工具发挥作用,同时把这些常量放在单独的文件中可 ...

  3. Linux正则表达式题型

    1.将下面的/etc/passwd所有行的第一列和最后一列相互调换位置. 解答: 1)使用sed的后向引用 2)awk -F ":" '{print $7":" ...

  4. python 下安装pymysql应用

    前言 pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb几乎相同.但目前pymysql支持python3.x而后者不支持3.x版本. 本文测试python版本:2.7.11. ...

  5. c++学习笔记之类模板

    C++ 除了支持函数模板,还支持类模板(Class Template).函数模板中定义的类型参数可以用在函数声明和函数定义中,类模板中定义的类型参数可以用在类声明和类实现中.类模板的目的同样是将数据的 ...

  6. 同一台服务器请求easyswoole的一个websocket接口报错

    求助大神啊!file_get_contents报这个错:failed to open stream: Connection timed out换成curl又报这个错:couldn't connect ...

  7. tr、od命令

    一.tr:替换或删除字符 语法:       tr [OPTION] ... SET1 [SET2] 描述       翻译,压缩和/或删除标准输入中的字符,可写吗?       到标准输出. -c, ...

  8. Spring实战(十三)Spring事务

    1.什么是事务(Transaction)? 事务是指逻辑上的一组操作,要么全部成功,要么全部失败. 事务是指将一系列数据操作捆绑成为一个整体进行统一管理.如果某一事务执行成功,则该事务中进行的所有数据 ...

  9. 你懂什么是分布式系统吗?Redis分布式锁都不会?

    分布式系统涉及到很多的技术.理论与协议,很多人也说,分布式系统是“入门容易,深入难”,有一些人简历上写着熟悉分布式系统,很多人都是管中窥豹只见一斑. 究竟什么是分布式系统? 分布式系统是由一组通过网络 ...

  10. springMVC 接受map参数的写法

    <form > <input type="hidden" name="map['userKey']" value="11111&qu ...