Android 显示或隐藏标题栏进度条TitleProgressBar
1.新建项目,布局文件如下:activity_main.xml
1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2 xmlns:tools="http://schemas.android.com/tools"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:layout_marginLeft="10dp"
6 android:orientation="vertical" >
7
8 <Button
9 android:id="@+id/btn1"
10 android:layout_width="wrap_content"
11 android:layout_height="wrap_content"
12 android:text="显示" />
13
14 <Button
15 android:id="@+id/btn2"
16 android:layout_width="wrap_content"
17 android:layout_height="wrap_content"
18 android:text="隐藏" />
19
20 </LinearLayout>
2.后台代码如下:MainActivity.java
1 package com.example.testdemo;
2
3 import android.app.Activity;
4 import android.os.Bundle;
5 import android.view.View;
6 import android.view.View.OnClickListener;
7 import android.view.Window;
8 import android.widget.Button;
9
10 public class MainActivity extends Activity {
11
12 @Override
13 protected void onCreate(Bundle savedInstanceState) {
14 super.onCreate(savedInstanceState);// 以下两句代码必须写在setContentView之前否则不起作用
15 requestWindowFeature(Window.FEATURE_PROGRESS);// 进度指示器功能
16 requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); // 不确定的进度
17 setContentView(R.layout.activity_main);
18 Button btn1 = (Button) findViewById(R.id.btn1);
19 Button btn2 = (Button) findViewById(R.id.btn2);
20 // 展示标题栏进度条
21 btn1.setOnClickListener(new OnClickListener() {
22 @Override
23 public void onClick(View v) {
24 setProgressBarVisibility(true);
25 setProgressBarIndeterminateVisibility(true);
26 }
27 });
28 // 隐藏标题栏进度条
29 btn2.setOnClickListener(new OnClickListener() {
30 @Override
31 public void onClick(View v) {
32 setProgressBarVisibility(false);
33 setProgressBarIndeterminateVisibility(false);
34 }
35 });
36 }
37 }
3.效果如如下: