Spinner的简单用法和功能(二)
主要讲在标题栏的进度条
布局就是两个简单的显示和隐藏按钮
<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="horizontal">
<Button android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="显示" />
<Button android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="隐藏" />
</LinearLayout>
代码部分
package com.test.progressbar2;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
public class MainActivity extends Activity {
private Button button1;
private Button button2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//设置窗口特征;启用显示进度的进度条
requestWindowFeature(Window.FEATURE_PROGRESS);
//设置窗口特征;启用隐藏进度的进度条
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_main);
button1 = (Button)findViewById(R.id.button1);
button2 = (Button)findViewById(R.id.button2);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//显示不带进度的进度条
setProgressBarIndeterminateVisibility(true);
//显示带进度的进度条
setProgressBarVisibility(true);
//设置进度条的嫉妒
setProgress(4500);
}
});
button2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//隐藏不带进度的进度条
setProgressBarIndeterminateVisibility(false);
//隐藏带进度的进度条
setProgressBarVisibility(false);
}
});
}
}