requestWindowFeature能夠設置的值有:
// 1.DEFAULT_FEATURES:系統默認狀態,通常不須要指定
// 2.FEATURE_CONTEXT_MENU:啓用ContextMenu,默認該項已啓用,通常無需指定
// 3.FEATURE_CUSTOM_TITLE:自定義標題。當須要自定義標題時必須指定。如:標題是一個按鈕時
// 4.FEATURE_INDETERMINATE_PROGRESS:不肯定的進度
// 5.FEATURE_LEFT_ICON:標題欄左側的圖標
// 6.FEATURE_NO_TITLE:無標題
// 7.FEATURE_OPTIONS_PANEL:啓用「選項面板」功能,默認已啓用。
// 8.FEATURE_PROGRESS:進度指示器功能
// 9.FEATURE_RIGHT_ICON:標題欄右側的圖標
效果圖:
default:
progress: android
no title: app
lefticon: ide
fullscreen:
indeterminate_progress:
this
customtitle: 線程
代碼:
package com.my; get
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Window;
import android.view.WindowManager; it
public class WindowFeatureDemoActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// requestWindowFeature();的取值
// 1.DEFAULT_FEATURES:系統默認狀態,通常不須要指定
// 2.FEATURE_CONTEXT_MENU:啓用ContextMenu,默認該項已啓用,通常無需指定
// 3.FEATURE_CUSTOM_TITLE:自定義標題。當須要自定義標題時必須指定。如:標題是一個按鈕時
// 4.FEATURE_INDETERMINATE_PROGRESS:不肯定的進度
// 5.FEATURE_LEFT_ICON:標題欄左側的圖標
// 6.FEATURE_NO_TITLE:無標題
// 7.FEATURE_OPTIONS_PANEL:啓用「選項面板」功能,默認已啓用。
// 8.FEATURE_PROGRESS:進度指示器功能
// 9.FEATURE_RIGHT_ICON:標題欄右側的圖標
// ========================FEATURE_INDETERMINATE_PROGRESS:不肯定的進度
// showFEATURE_INDETERMINATE_PROGRESS();
// // =====================FEATURE_CUSTOM_TITLE
// showFEATURE_CUSTOM_TITLE();
// // ======================== FEATURE_LEFT_ICON:標題欄左側的圖標
// showFEATURE_LEFT_ICON();
// // ======================FEATURE_NO_TITLE
// showFEATURE_NO_TITLE();
// =================================FEATURE_PROGRESS
showFEATURE_PROGRESS(); io
} class
private void showFEATURE_INDETERMINATE_PROGRESS() {
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, R.layout.progress);
// 必須得加上不然顯示不出效果 能夠經過這個在之後設置顯示或隱藏
setProgressBarIndeterminateVisibility(true);
} import
private void showFEATURE_CUSTOM_TITLE() {
// 自定義標題。當須要自定義標題時必須指定。如:標題是一個按鈕時
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.customtitle);
}
private void showFEATURE_LEFT_ICON()
{
requestWindowFeature(Window.FEATURE_LEFT_ICON);
setContentView(R.layout.main);
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
R.drawable.icon);
}
private void showFEATURE_NO_TITLE()
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
// 加上這句設置爲全屏 不加則只隱藏title
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
private void showFEATURE_PROGRESS()
{
requestWindowFeature(Window.FEATURE_PROGRESS);
setProgressBarVisibility(true);
setContentView(R.layout.main);
setTitle("");
getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
// 經過線程來改變ProgressBar的值
new Thread(new Runnable() {
public void run() {
for (int i = 0; i < 10; i++) {
try {
Thread.sleep(1000);
Message m = new Message();
m.what = (i + 1) * 20;
WindowFeatureDemoActivity.this.myMessageHandler.sendMessage(m);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}).start();
}
Handler myMessageHandler = new Handler() {
// @Override
public void handleMessage(Message msg) {
// 設置標題欄中前景的一個進度條進度值
setProgress(100 * msg.what);
// 設置標題欄中後面的一個進度條進度值
setSecondaryProgress(100 * msg.what + 10);
super.handleMessage(msg);
}
};
}