ProgressDialog 进度条的初步认识
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 进度条的初步认识的更多相关文章
- android学习笔记20——ProgressDialog进度条对话框
ProgressDialog==>进度条对话框 ProgressDialog本身就代表一个进度条对话框,程序只需要创建ProgressDialog实例,并将其显示出来就是一个进度条对话框:开发者 ...
- Android——ProgressDialog 进度条对话框
public class ProgressDialogActivity extends Activity { private Button btn_large_pd, btn_horizonta ...
- 【转】【Android】ProgressDialog进度条对话框的使用
Android ProgressDialog进度条对话框的使用: 转自:http://aina-hk55hk.iteye.com/blog/679134/ <?xml version=" ...
- 【转】24. android dialog ——ProgressDialog 进度条对话框详解
原文网址:http://blog.csdn.net/jamesliulyc/article/details/6375598 首先在onCreateDialog方法里创建一个ProgressDialog ...
- ProgressDialog进度条对话框
(一) 1.效果图: 2.activity_main.xml <?xml version="1.0" encoding="utf-8"?> < ...
- android 对话框中的进度条 (ProgressDialog)
from:http://byandby.iteye.com/blog/817214 显然要定义对话框进度条就要用ProgressDialog,首先我们需要创建ProgressDialog对象,当然这里 ...
- Android 进度条对话框ProgressDialog
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- 10.Android之ProgressDialog进度对话框学习
APP应用中经常会下载某些东西,这里面有涉及到进度对话框,今天来学习下. 首先,布局里放进两个按钮,点击一个显示条形进度条,另一个显示圆形进度条.代码如下: <?xml version=&quo ...
- (转载)Android自定义ProgressDialog进度等待框
Android自定义ProgressDialog进度等待框 作者:无缘公子 字体:[增加 减小] 类型:转载 时间:2016-01-11我要评论 这篇文章主要介绍了Android自定义Progress ...
随机推荐
- composer install与composer update的区别
1.composer install install 命令从当前目录读取 composer.json 文件,处理了依赖关系,并把其安装到 vendor 目录下. php composer.phar i ...
- Java中验证编码格式的一种方法
package forlittlecatty; import java.io.File; import java.io.FileInputStream; import java.io.IOExcept ...
- DRF之APIView源码解析
目录 Django项目中的代码如下 APIView源码解析 源码解析总结 Django项目中的代码如下 urls.py中: from django.conf.urls import url from ...
- Python os 使用
python os 使用 1. 获取文件所在路径 import os os.path.dirname(__file__) 获取当前文件的所在路径 print (os.path.dirname(os. ...
- hydra 使用
Hydra介绍 Hydra是一个并行登录破解器,支持多种攻击协议.它非常快速和灵活,新模块易于添加.该工具使研究人员和安全顾问能够展示远程获得对系统未经授权的访问是多么容易. 它支持:Cisco AA ...
- sql 循环转移备份数据
--创建表结构 select top 1 * into ATable_20190710 from ATable --转移表数据 insert into ATable_20190710 select t ...
- 2019-07-30 C#基础知识学习
继承和多态 接口与抽象类的区别:1.在接口中仅能定义成员,但是不能有具体的实现:抽象类除了抽象成员以外,其他成员有具体的实现.2.在接口中不能声明字段,并且不能声明任何私有成员,成员不能包含任何修饰符 ...
- 使用批处理执行 sql cmd
当 sql脚本文件太大了, 就可以考虑用这个方式来执行 1.准备好要执行的 sql脚本文件并保存为*.sql格式 2.找到 SQLCMD.EXE 文件所在的路径(每个版本sql路径不一样) C:\Pr ...
- Golang 无法下载依赖 golang.org (GoLand解决方法)
如下图所示将Proxy设置为:https://goproxy.io/
- PAT B1041 考试座位号(15)
解题要点: 使用结构体保存准考证号,考试座位号 试机座位号作考生数组下标 通过试机座位号获取考生号,座位号 考生号使用long long存放 //课本AC代码 #include <cstdio& ...