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. PHP读书笔记(7)- 函数

    自定义函数 PHP内置了超过1000个函数,因此函数使得PHP成为一门非常强大的语言.大多数时候我们使用系统的内置函数就可以满足需求,但是自定义函数通过将一组代码封装起来,使代码进行复用,程序结构与逻 ...

  2. 在vs环境中跑动sift特征提取(代码部分)

    因为在前两天的学习中发现.在opencv环境中跑动sift特征点提取还是比较困难的. 所以在此,进行记述. 遇到的问题分别有,csdn不愿意花费积分.配置gtk困难.教程海量然而能跑者鲜.描述不详尽等 ...

  3. linux - 文件查找及压缩

    文件查找: 1.  which    查找可以执行文件,只搜索$PATH里的目录 $ which ls /bin/ls which只搜索$PATH里的目录,如果搜索当前目录的文件是没有任何结果的 $ ...

  4. CSS设置行内元素和块级元素的水平居中、垂直居中

    CSS设置行内元素的水平居中 div{text-align:center} /*DIV内的行内元素均会水平居中*/ CSS设置行内元素的垂直居中 div{height:30px; line-heigh ...

  5. vim 编辑器 打开GB2312、GBK文件乱码解决方法

    安装好的操作系统一般都带有vim编辑器,但是默认不支持GB2312中文,打开文件出现乱码,解决办法如下. 1.打开以下文件 sudo vim /var/lib/locales/supported.d/ ...

  6. JDK的安装

    安装jdk解压拷贝过来的jdk(1.6版本)压缩包 cd /usr/local/tar xzvf /tmp/jdk.tgz 修改环境变量vi /etc/profile 加入如下内容export JAV ...

  7. LeetCode 11

    Container With Most Water Given n non-negative integers a1, a2, ..., an, where each represents a poi ...

  8. [改善Java代码]Java的泛型是类型擦除的

    泛型可以减少强制类型的转换,可规范集合的元素类型,还可以提高代码的安全性和可读性,正是因为有了这些优点,自从Java引入泛型之后,项目的编码规则上便多了一条,优先使用泛型. Java泛型(Generi ...

  9. [改善Java代码]Lock与synchronized是不一样的

    很多编码者都会还说,Lock类和synchronized关键字用在代码块的并发性和内存上时语义是一样的.

  10. 【简单dp+模拟】hdu-5375(2015多校#7-1007)

    给你一个二进制数,,每一位有一个权值,让你转格雷码,求所对应格雷码位为1的权值的和:二进制位中的某些位为?,你需要给这些问号赋值使得到的和最大. 首先你得知道二进制转格雷码的规则,即格雷码位为[二进制 ...