xml文件:
<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="com.example.app3.MainActivity2" > <ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="61dp"
android:layout_marginTop="45dp" android:indeterminate="true"/>
<!-- indeterminate 不确定 --> <ProgressBar
android:id="@+id/progressBar2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/progressBar1"
android:layout_marginLeft="18dp"
android:layout_toRightOf="@+id/progressBar1" /> <ProgressBar
android:id="@+id/progressBar3"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/progressBar2"
android:indeterminateDrawable="@drawable/progress_bg"
android:layout_below="@+id/progressBar1" />
<!-- 自定义progressBar --> <ProgressBar
android:id="@+id/progressBar4"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/progressBar1"
android:layout_alignParentRight="true"
android:layout_below="@+id/progressBar1"
android:layout_marginTop="46dp"
android:max="100"
android:progress="50"
android:secondaryProgress="80" />
<!-- secondaryProgress 第二进度条进度值(缓冲) --> <Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/progressBar4"
android:layout_alignRight="@+id/progressBar4"
android:layout_below="@+id/progressBar4"
android:text="对话框进度条"
android:onClick="showDialogProgress"/> </RelativeLayout>
源代码:
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window; public class MainActivity3 extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//设置特性以允许在应用程序的标题栏上显示进度条(条状)
//requestWindowFeathre(WIndow.FEATURE_PROGRESS); //设置特性以允许在应用程序的标题栏上显示进度条(圆圈状)
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
//在标题栏上显示进度条(条状)
// setProgressBarVisibility(true);
//在标题栏上显示进度条(圆圈状)
setProgressBarIndeterminateVisibility(true);
setContentView(R.layout.activity_main3); }
/*
* 显示对话框进度条
*/
public void showDialogProgress(View v){
/*//创建对话框进度条
ProgressDialog pd = new ProgressDialog(this);
pd.setMax(100);
pd.setProgress(30);
//pd.setIndeterminate(false);
pd.setCancelable(true);//是否能被取消
pd.setTitle("下载对话框");
pd.setMessage("正在下载中");
pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);//设置水平样式
pd.show();*/
//简洁对话框进度条
ProgressDialog pd2 = ProgressDialog.show(this, "download", "downLoading...",false);
} }