2011年9月19日星期一

顯示標題進度條, setProgressBarIndeterminateVisibility()

要在標題欄顯示進度條, 首先在 setContentView() 前調用 requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS) 函數要求FEATURE_INDETERMINATE_PROGRESS 功能. 再通過調用 setProgressBarIndeterminateVisibility(true/false) 函數顯示/隱藏標題進度條.

顯示標題進度條

package com.AndroidProgressTitle;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;

public class AndroidProgressTitleActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.main);

Button showProgress = (Button)findViewById(R.id.showprogress);
Button hideProgress = (Button)findViewById(R.id.hideprogress);

showProgress.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
setProgressBarIndeterminateVisibility(true);
}});

hideProgress.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
setProgressBarIndeterminateVisibility(false);
}});
}
}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:id="@+id/showprogress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="顯示標題進度條"
/>
<Button
android:id="@+id/hideprogress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="隱藏標題進度條"
/>
</LinearLayout>

沒有留言:

發佈留言