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 ...
随机推荐
- Docker知识点总结
一. docker介绍: 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化.容器是完全使用沙箱机制,相互之间不 ...
- 【VS开发】EasySize使用设置CFormView空间自适应view窗口大小
1.在stdafx.h中引用EasySize.h头文件(同时将EasySize.h放到你的程序目录中) 2.在类定义中添加DECLARE_EASYSIZE [cpp] view plain copy ...
- pubwin扫描安装
1,注意顺序 先安装一代 FS533 2,在安装精伦 3,在重新注册 PUBWIN 如果还不行一般是注册商没给注册好
- JAVA实验报告及第七周总结
JAVA第六周作业 实验报告五 第一题 1.设计一个类层次,定义一个抽象类--形状,其中包括有求形状的面积的抽象方法. 继承该抽象类定义三角型.矩形.圆. 分别创建一个三角形.矩形.圆存对象,将各类图 ...
- Maximum Frequency Stack
Implement FreqStack, a class which simulates the operation of a stack-like data structure. FreqStack ...
- SQLServer学习之表的操作
SQLServer学习之表的操作 关系数据库通常包含多个表.数据库实际上是表的集合,数据库的数据或者信息都是存储在表中的.表是对数据进行存储和操作的一种逻辑结构,每一个表都代表一个对用户意义的对象. ...
- python入门小结
以下划线开头的标识符是有特殊意义的.以单下划线开头(_foo)的代表不能直接访问的类属性,需通过类提供的接口进行访问,不能用"from xxx import *"而导入: 以双下划 ...
- Zookeeper 配置和原理探究
一 Zookeeper是什么? 服务集群对外提供服务的过程中,有很多的配置需要随时更新,服务间需要协调工作,那么这些信息如何推送到各个节点?并且保证信息的一致性和可靠性?我们知道分布式协调服务很难正确 ...
- PAT B1026.程序运行时间
AC代码 #include <cstdio> #define CLK_TCK 100 int main() { int C1, C2, C3; scanf("%d%d" ...
- 剑指offer7: 斐波那契数列第n项(从0开始,第0项为0)
1. 题目描述 大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0).n<=39 2. 思路和方法 斐波那契数列(Fibonacci sequen ...