废话不多说,直接上代码
Main代码
package processdemo.example.administrator.processbardemo;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
/*ProgressBar
简介:ProgressBar是进度条组件,通常用于向用户展示某个耗时操作完成的进度,而不让用户感觉是程序失去了响应,从而更好地提升用户界面的友好性
课程目标:
1、制定ProgressBar显示风格(系统默认)
2、ProgressBar的分类
水平进度条,能精确显示,圆圈进度条,不精确显示
3、标题上ProgressBar的设置
4、ProgressBar的关键属性
5、ProgressBar的关键方法
6、ProgressDiglog的基础使用
7、自定义ProgressBar样式*/
private ProgressBar progressBar3;
private Button show;
private Button add;
private Button res;
private Button reset;
private TextView textView;
private ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 启用窗口特征,启用带进度的进度条和不带进度的进度条,
requestWindowFeature(Window.FEATURE_PROGRESS);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_main);
setProgressBarVisibility(true);
setProgressBarIndeterminateVisibility(false);
// 最大值为Max=10000;
//setProgress(600);
init();
}
private void init() {
;
progressBar3= (ProgressBar) findViewById(R.id.progressBar3);
show= (Button) findViewById(R.id.show);
add= (Button) findViewById(R.id.add);
res= (Button) findViewById(R.id.res);
reset= (Button) findViewById(R.id.reset);
textView= (TextView) findViewById(R.id.textView);
int first=progressBar3.getProgress();/*获取第一进度*/
int second=progressBar3.getSecondaryProgress();/*获取第二进度*/
int max=progressBar3.getMax();/*获取最大进度*/
textView.setText("第一进度条百分比"+(int)((first/(float)max)*100)+"%"+"第二进度条百分比"+(int)(second/(float)max*100)+"%");
add.setOnClickListener(this);
res.setOnClickListener(this);
reset.setOnClickListener(this);
show.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.add:
progressBar3.incrementProgressBy(10);
progressBar3.incrementSecondaryProgressBy(10);
break;
case R.id.res:
progressBar3.incrementProgressBy(-10);
progressBar3.incrementSecondaryProgressBy(-10);
break;
case R.id.reset:
progressBar3.setProgress(50);
progressBar3.setSecondaryProgress(50);
break;
case R.id.show:
// 新建ProgressDialog对象
progressDialog=new ProgressDialog(MainActivity.this);
// 设置显示风格
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
// 设置标题
progressDialog.setTitle("慕课网");
// 设置对话框的内容
progressDialog.setMessage("欢迎大家支持慕课网");
// 设置图标
progressDialog.setIcon(R.mipmap.ic_launcher);
/*设置关于进度条的一些属性*/
// 设置最大进度
progressDialog.setMax(100);
// 设置初始化已经增长的进度
progressDialog.incrementProgressBy(50);
// 设置进度条明确显示进度
progressDialog.setIndeterminate(false);
/* 设定一个确定按钮*/
progressDialog.setButton(DialogInterface.BUTTON_POSITIVE,"确定", new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this,"欢迎大家支持慕课网",Toast.LENGTH_SHORT).show();
}
});
// 是否可以通过返回按钮来取消对话框
progressDialog.setCancelable(true);
// 显示ProgressDialog
progressDialog.show();
}
textView.setText("第一进度条百分比"+(int)((progressBar3.getProgress()/(float)progressBar3.getMax())*100)+"%"+"第二进度条百分比"+(int)(progressBar3.getSecondaryProgress()/(float)progressBar3.getMax()*100)+"%");
}
}
layout中activity_main.xml代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="processdemo.example.administrator.processbardemo.MainActivity">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginTop="112dp" />
<ProgressBar
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar2"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="256dp" />
<ProgressBar
style="@android:style/Widget.ProgressBar.Horizontal"
android:max="100"
android:progress="50"
android:secondaryProgress="80"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar3"
android:layout_alignParentBottom="true"
android:layout_alignStart="@+id/progressBar2"
android:layout_marginBottom="81dp"
android:layout_alignTop="@+id/res"
android:progressDrawable="@layout/progress"/><!--progressDrawable改变样式-->
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar4"
android:layout_above="@+id/reset"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/增加"
android:id="@+id/add"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/减少"
android:id="@+id/res"
android:layout_above="@+id/add"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/重置"
android:id="@+id/reset"
android:layout_alignBottom="@+id/progressBar3"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="进度"
android:id="@+id/textView"
android:layout_below="@+id/progressBar"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/显示进度条"
android:id="@+id/show"
android:layout_below="@+id/progressBar2"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<!-- ProgressBar关键属性
1.android:max ---最大显示进度
2.android:progress ---第一显示进度
3.android:secondaryProgress---第二显示进度
4.android:isdeterminate ---设置是否精确显示(false为精确,true为不精确)-->
layout中progress.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<item android:id="@android:id/background">
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#76cf76"
android:centerColor="#125912"
android:centerY="0.75"
android:endColor="#212621"
android:angle="270"
/>
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#80b51638"
android:centerColor="#80a47d1a"
android:centerY="0.75"
android:endColor="#a066c3a7"
android:angle="270"
/>
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#a38c1c"
android:centerColor="#55a6b6"
android:centerY="0.75"
android:endColor="#b59826"
android:angle="270"
/>
</shape>
</clip>
</item>
</layer-list>
以上这篇进度条ProgressBar及ProgressDialog(实例)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
# 进度条ProgressBar及ProgressDialog
# Android ProgressDialog进度条使用详解
# 老生常谈ProgressBar、ProgessDialog的用法
# Android 七种进度条的样式
# Android 中通过实现线程更新Progressdialog (对话进度条)
# 解析android中ProgressBar的用法
# Android ProgressBar进度条使用详解
# 进度条
# 给大家
# 欢迎大家
# 对话框
# 不精确
# 可以通过
# 希望能
# 自定义
# 这篇
# 不带
# 多说
# 小编
# 值为
# 大家多多
# 失去了
# 更好地
# false
# background
# Max
# setProgressBarIndeterminateVisibility
相关文章:
宁波自助建站系统如何快速打造专业企业网站?
如何在阿里云购买域名并搭建网站?
mc皮肤壁纸制作器,苹果平板怎么设置自己想要的壁纸我的世界?
如何在香港免费服务器上快速搭建网站?
宠物网站制作html代码,有没有专门介绍宠物如何养的网站啊?
北京网站制作的公司有哪些,北京白云观官方网站?
如何基于云服务器快速搭建网站及云盘系统?
如何破解联通资金短缺导致的基站建设难题?
如何访问已购建站主机并解决登录问题?
c# 在高并发场景下,委托和接口调用的性能对比
如何快速搭建响应式可视化网站?
微网站制作教程,我微信里的网站怎么才能复制到浏览器里?
如何通过服务器快速搭建网站?完整步骤解析
制作门户网站的参考文献在哪,小说网站怎么建立?
,南京靠谱的征婚网站?
制作网站怎么制作,*游戏网站怎么搭建?
教程网站设计制作软件,怎么创建自己的一个网站?
定制建站平台哪家好?企业官网搭建与快速建站方案推荐
代购小票制作网站有哪些,购物小票的简要说明?
如何挑选高效建站主机与优质域名?
如何通过虚拟主机空间快速建站?
高防服务器租用指南:配置选择与快速部署攻略
如何撰写建站申请书?关键要点有哪些?
合肥制作网站的公司有哪些,合肥聚美网络科技有限公司介绍?
哈尔滨网站建设策划,哈尔滨电工证查询网站?
如何挑选优质建站一级代理提升网站排名?
怎么将XML数据可视化 D3.js加载XML
如何用PHP快速搭建CMS系统?
如何在香港服务器上快速搭建免备案网站?
成都网站制作公司哪家好,四川省职工服务网是做什么用?
岳西云建站教程与模板下载_一站式快速建站系统操作指南
建站之星导航如何优化提升用户体验?
建站168自助建站系统:快速模板定制与SEO优化指南
标准网站视频模板制作软件,现在有哪个网站的视频编辑素材最齐全的,背景音乐、音效等?
英语简历制作免费网站推荐,如何将简历翻译成英文?
Python多线程使用规范_线程安全解析【教程】
小型网站建站如何选择虚拟主机?
如何选择可靠的免备案建站服务器?
深圳网站制作费用多少钱,读秀,深圳文献港这样的网站很多只提供网上试读,但有些人只要提供试读的文章就能全篇下载,这个是怎么弄的?
网站制作免费,什么网站能看正片电影?
如何通过VPS搭建网站快速盈利?
如何生成腾讯云建站专用兑换码?
如何在橙子建站中快速调整背景颜色?
如何在阿里云虚拟服务器快速搭建网站?
ppt在线制作免费网站推荐,有什么下载免费的ppt模板网站?
建站主机是否等同于虚拟主机?
如何快速搭建高效服务器建站系统?
建站之星3.0如何解决常见操作问题?
黑客如何通过漏洞一步步攻陷网站服务器?
如何用IIS7快速搭建并优化网站站点?
*请认真填写需求信息,我们会在24小时内与您取得联系。