2011年7月22日星期五

在標題欄顯示進度圖標 - Window.FEATURE_INDETERMINATE_PROGRESS

要在標題欄顯示進度圖標, 先要要求窗口功能"Window.FEATURE_INDETERMINATE_PROGRESS":
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

再調用 setProgressBarIndeterminateVisibility(true/false) 方法來顯示/隱藏它.

實例:
在標題欄顯示進度圖標 - Window.FEATURE_INDETERMINATE_PROGRESS

package com.AndroidProgressTitleBar;

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

public class AndroidProgressTitleBarActivity 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 btnTurnOnProgress = (Button)findViewById(R.id.progresson);
Button btnTurnOffProgress = (Button)findViewById(R.id.progressoff);

btnTurnOnProgress.setOnClickListener(new Button.OnClickListener(){

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

btnTurnOffProgress.setOnClickListener(new Button.OnClickListener(){

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


沒有留言:

發佈留言