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:
no title:
lefticon:
fullscreen:
indeterminate_progress:
customtitle:
1 代码: 2 package com.my; 3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.os.Handler; 6 import android.os.Message; 7 import android.view.Window; 8 import android.view.WindowManager; 9 public class WindowFeatureDemoActivity extends Activity {10 @Override11 public void onCreate(Bundle savedInstanceState) {12 super.onCreate(savedInstanceState);13 // requestWindowFeature();的取值14 // 1.DEFAULT_FEATURES:系统默认状态,一般不需要指定15 // 2.FEATURE_CONTEXT_MENU:启用ContextMenu,默认该项已启用,一般无需指定16 // 3.FEATURE_CUSTOM_TITLE:自定义标题。当需要自定义标题时必须指定。如:标题是一个按钮时17 // 4.FEATURE_INDETERMINATE_PROGRESS:不确定的进度18 // 5.FEATURE_LEFT_ICON:标题栏左侧的图标19 // 6.FEATURE_NO_TITLE:无标题20 // 7.FEATURE_OPTIONS_PANEL:启用“选项面板”功能,默认已启用。21 // 8.FEATURE_PROGRESS:进度指示器功能22 // 9.FEATURE_RIGHT_ICON:标题栏右侧的图标23 // ========================FEATURE_INDETERMINATE_PROGRESS:不确定的进度24 // showFEATURE_INDETERMINATE_PROGRESS();25 // // =====================FEATURE_CUSTOM_TITLE 26 // showFEATURE_CUSTOM_TITLE();27 // // ======================== FEATURE_LEFT_ICON:标题栏左侧的图标28 // showFEATURE_LEFT_ICON();29 // // ======================FEATURE_NO_TITLE30 // showFEATURE_NO_TITLE(); 31 // =================================FEATURE_PROGRESS32 showFEATURE_PROGRESS();33 }34 private void showFEATURE_INDETERMINATE_PROGRESS() {35 requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);36 setContentView(R.layout.main);37 getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, R.layout.progress);38 // 必须得加上否则显示不出效果 可以通过这个在以后设置显示或隐藏39 setProgressBarIndeterminateVisibility(true);40 }41 private void showFEATURE_CUSTOM_TITLE() {42 // 自定义标题。当需要自定义标题时必须指定。如:标题是一个按钮时43 requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);44 setContentView(R.layout.main);45 getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.customtitle);46 }47 private void showFEATURE_LEFT_ICON()48 {49 requestWindowFeature(Window.FEATURE_LEFT_ICON);50 setContentView(R.layout.main);51 getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,52 R.drawable.icon);53 }54 private void showFEATURE_NO_TITLE()55 {56 requestWindowFeature(Window.FEATURE_NO_TITLE);57 setContentView(R.layout.main);58 // 加上这句设置为全屏 不加则只隐藏title59 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,60 WindowManager.LayoutParams.FLAG_FULLSCREEN);61 }62 private void showFEATURE_PROGRESS()63 {64 requestWindowFeature(Window.FEATURE_PROGRESS);65 setProgressBarVisibility(true);66 setContentView(R.layout.main);67 setTitle("");68 getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);69 // 通过线程来改变ProgressBar的值70 new Thread(new Runnable() {71 public void run() {72 for (int i = 0; i < 10; i++) {73 try {74 Thread.sleep(1000);75 Message m = new Message();76 m.what = (i + 1) * 20;77 WindowFeatureDemoActivity.this.myMessageHandler.sendMessage(m);78 } catch (Exception e) {79 e.printStackTrace();80 }81 }82 }83 }).start();84 }85 Handler myMessageHandler = new Handler() {86 // @Override87 public void handleMessage(Message msg) {88 // 设置标题栏中前景的一个进度条进度值89 setProgress(100 * msg.what);90 // 设置标题栏中后面的一个进度条进度值91 setSecondaryProgress(100 * msg.what + 10);92 super.handleMessage(msg);93 }94 };95 }