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. JavaScript(9)—— CSS定位综合练习

    画布上画矩形 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  2. python 输出对齐

    几种不同类型的输出对齐总结: 先看效果: 采用.format打印输出时,可以定义输出字符串的输出宽度,在 ':' 后传入一个整数, 可以保证该域至少有这么多的宽度. 用于美化表格时很有用. >& ...

  3. 关于MYSQL使用过程中的一些错误总结

    一,java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 导致这个问题有很多种情况,我暂时遇到的是:未在lib下导入jar包. 这个链接是各个 ...

  4. Golang 匿名结构体及测试代码编写技巧

    转自: https://www.jianshu.com/p/901820e17ffb 结构体基础 结构体 (struct) 将多个不同类型的字段集中组成一种复合类型,按声明时的字段顺序初始化. typ ...

  5. python中的FQA (python 学习篇 1)

    Q:1.  "  if __name__=='__main__'   "  这句是什么意思,可以不加吗? A:   如果单独运行该文件,则该模块的内容会被执行: 若运行的文件引用该 ...

  6. 设置gridView 行号 行号宽

    gridView1.IndicatorWidth=30; //设置行号宽度 //对gridView1的CustomDrawRowIndicator事件进行操作 进行行号显示 private stati ...

  7. jstl与EL表达式

    一·el表达式介绍 EL 全名为Expression Language EL 语法很简单,它最大的特点就是使用上很方便.接下来介绍EL主要的语法结构: ${sessionScope.user.sex} ...

  8. Thinkphp+Ajax带关键词搜索列表无刷新分页实例

    Thinkphp+Ajax带关键词搜索列表无刷新分页实例,两个查询条件,分页和搜索关键字,懂的朋友还可以添加其他分页参数. 搜索#keyword和加载内容区域#ajax_lists <input ...

  9. selenium 鼠标,键盘操作

    1.打开和关闭网页 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 #!/usr/bin/env python # -*- coding:u ...

  10. 并不对劲的P5589

    题目大意 有\(n\)(\(n\leq 10^9\))个数:\(1,2,...,n\),每次操作是随机取一个没被删除的数\(x\),并删去\(x,x^2,x^3,...\). 求期望几次删完所有数. ...