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;@Overrideprotected 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);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {getMenuInflater().inflate(R.menu.main, menu);return true;}@Overridepublic 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.显示效果

更多相关文章

  1. 我的Android进阶之旅------>Android视频录制小例子
  2. Android--利用selector设置Button
  3. Android(安卓)设置全屏显示
  4. Android底部导航栏实现(三)之TextView+LinearLayout
  5. android 中 浏览器调用本地app应用
  6. Android中设置关键字高亮的方法
  7. Android写文件到SDCard的一般过程和代码
  8. ntfs在android平台上的移植
  9. Android(安卓)Apk反编译、签名

随机推荐

  1. 在MySQL中自定义参数的使用详解
  2. 关于MySQL自增ID的一些小问题总结
  3. Mysql悲观锁和乐观锁的使用示例
  4. mysql 8.0.13 安装配置图文教程
  5. ERROR 2002 (HY000): Can&#39;t connect
  6. CentOS 6.2 安装 MySQL 5.7.28的教程(mys
  7. ERROR 1862 (HY000): Your password has
  8. Windows 下 MySQL 8.X 的安装教程
  9. CentOS 7 安装解压版mysql5.7的教程
  10. MySql实现翻页查询功能