1.xml文件 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:orientation="vertical" > <ProgressBar
android:id="@+id/progressBar01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <ProgressBar
android:id="@+id/progressBar02"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <ProgressBar
android:id="@+id/progressBar03"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> <ProgressBar
android:id="@+id/progressBar04"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="100"
android:progress="20"
android:secondaryProgress="60" /> <Button
android:id="@+id/increment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/increment" /> <Button
android:id="@+id/decrement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/decrement" /> <Button
android:id="@+id/showDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="showDialog"
android:text="@string/showDialog" /> <ProgressBar
android:id="@+id/progressBar05"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminateDrawable="@drawable/pb_custom" /> </LinearLayout>

  2.string.xml

<?xml version="1.0" encoding="utf-8"?>
<resources> <string name="app_name">Android_019</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string> <string name="increment">增加</string>
<string name="decrement">减少</string>
<string name="showDialog">显示进度条对话框</string> </resources>

  3.MainActivity.java

package com.example.android_019;

import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ProgressBar; /**
* 进度条的实现方法
* @author hbj403
*/
public class MainActivity extends Activity implements OnClickListener{ private Button btnIncrement,btnDecrement;
private ProgressBar pb01; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); //设置标题栏进度条 注意 一定要在setContentView方法之前定义
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.activity_main); //设置标题栏为启动接可见
setProgressBarIndeterminateVisibility(true); btnIncrement=(Button) findViewById(R.id.increment);
btnIncrement.setOnClickListener(this); btnDecrement=(Button) findViewById(R.id.decrement);
btnDecrement.setOnClickListener(this); pb01=(ProgressBar) findViewById(R.id.progressBar04); } @Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
} @Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.increment:
pb01.incrementProgressBy(10);
pb01.setSecondaryProgress(40);
break;
case R.id.decrement:
pb01.incrementProgressBy(-10);
pb01.setSecondaryProgress(-40);
break;
default:
break;
}
} //显示对话框进度条
public void showDialog(View view){
//ProgressDialog.show(this, "标题", "文件正在下载中...", true, true); 直接设置对话框的属性 ProgressDialog pd=new ProgressDialog(this); pd.setIcon(R.drawable.ic_launcher);
pd.setTitle("下载对话框");
pd.setMessage("文件正在下载中...");
pd.setMax(100);
//设置对对话框的样式
pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); pd.show(); } }

  4.图片Z1

5.显示效果

Android的ProgressBar以及自定义进度条的更多相关文章

  1. android 自定义进度条颜色

    android 自定义进度条颜色 先看图 基于产品经理各种自定义需求,经过查阅了解,下面是自己对Android自定义进度条的学习过程!   这个没法了只能看源码了,还好下载了源码, sources\b ...

  2. Android自定义进度条颜色

    这个没法了只能看源码了,还好下载了源码, sources\base\core\res\res\ 下应有尽有,修改进度条颜色只能找progress ,因为是改变样式,首先找styles.xml ? 1 ...

  3. C# 根据BackgroundWoker异步模型和ProgressBar控件,自定义进度条控件

    前言 程序开发过程中,难免会有的业务逻辑,或者算法之类产生让人能够感知的耗时操作,例如循环中对复杂逻辑处理;获取数据库百万乃至千万级数据;http请求的时候等...... 用户在使用UI操作并不知道程 ...

  4. android113 自定义进度条

    MainActivity: package com.itheima.monitor; import android.os.Bundle; import android.app.Activity; im ...

  5. 自定义进度条PictureProgressBar——从开发到开源发布全过程

    自定义进度条PictureProgressBar——从开发到开源发布全过程 出处: 炎之铠邮箱:yanzhikai_yjk@qq.com 本文原创,转载请注明本出处! 本项目JCenter地址:htt ...

  6. Android之ProgressBar读取文件进度解析

    ProgressBar进度条, 分为旋转进度条和水平进度条,进度条的样式根据需要自定义,之前一直不明白进度条如何在实际项目中使用,网上演示进度条的案例大多都是通过Button点 击增加.减少进度值,使 ...

  7. Qt之模型/视图(自定义进度条)

    简述 在之前的章节中分享过关于QHeaderView表头排序.添加复选框等内容,相信大家模型/视图.自定义风格有了一定的了解,下面我们来分享一个更常用的内容-自定义进度条. 实现方式: 从QAbstr ...

  8. Android再学习-20141018-布局-进度条

    20141018-Android再学习 对齐至控件的基准线 为了保证印刷字母的整齐而划定的线(四线三格的第三条线). android:layout_alignBaseline 与父控件的四个边缘对齐( ...

  9. BitBlt()函数实现带数字百分比进度条控件、静态文本(STATIC)控件实现的位图进度条、自定义进度条控件实现七彩虹颜色带数字百分比

    Windows API BitBlt()函数实现带数字百分比进度条控件. 有两个例子:一用定时器实现,二用多线程实现. 带有详细注解. 此例是本人原创,绝对是网上稀缺资源(本源码用Windows AP ...

随机推荐

  1. Debian 7.4 中配置PHP环境

    准备工作 导入密钥 wget http://www.dotdeb.org/dotdeb.gpg sudo apt-key add dotdeb.gpg 添加源 vi /etc/apt/sources. ...

  2. Linux 通过 load average 判断服务器负载情况

    Linux中load average判断服务器负载情况 转载文章 http://www.111cn.net/sys/linux/56003.htm 写的比较详细,推荐看看.

  3. oracle数据库性能调优

    一:注意WHERE子句中的连接顺序: ORACLE采用自下而上的顺序解析WHERE子句,根据这个原理,表之间的连接必须写在其他WHERE条件之前, 那些可以过滤掉最大数量记录的条件必须写在WHERE子 ...

  4. (转)嵌入式学习准备---linux c 文件锁

    (1)fcntl函数说明 前面的这5个基本函数实现了文件的打开.读写等基本操作,这一节将讨论的是,在文 件已经共享的情况下如何操作,也就是当多个用户共同使用.操作一个文件的情况,这时,Linux 通常 ...

  5. 去掉VC2010 编辑器里出现的红色波浪线

    在VC2010中浏览代码的时候就大片的红线看着不舒服 其实不关VS的事,原因在于visual assist.   在VAssistX菜单栏->Visual Assist X Options-&g ...

  6. Hive中自定义函数

    Hive的自定义的函数的步骤: 1°.自定义UDF extends org.apache.hadoop.hive.ql.exec.UDF 2°.需要实现evaluate函数,evaluate函数支持重 ...

  7. Vim编辑器的常用快捷键.

    Linux中的文本操作离不开Vim编辑器的使用. Vim编辑器的使用相对门槛较高.需要挺长一段时间的适应. 总结一些Vim使用过程中常用的命令(这些命令基本上都是在vim的命令模式下使用) 1.跳转到 ...

  8. https抓包判断证书问题

    openssl s_client -connect 61.135.250.130:443这个是reg.163.com的 tcpdump 也可

  9. Java Concurrency - ThreadLocal, 本地线程变量

    共享数据是多线程应用最常见的问题之一,但有时我们需要为每个线程保存一份独立的变量.Java API 提供了 ThreadLocal 来解决这个问题. 一个 ThreadLocal 作用的例子: imp ...

  10. Jersey(1.19.1) - Rules of Injection

    Previous sections have presented examples of annotated types, mostly annotated method parameters but ...