关于窗口样式的几个小例子 1 在窗体上显示图标和提示文字(即窗口的自定义标题) //MainActivity如下 package cn.ifeng.com; import android.app.Activity; import android.os.Bundle; import android.view.Window; public class WindowFeatureTestActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);//相当于告诉系统:我将自定义窗口标题布局 setContentView(R.layout.main); this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);//添加窗口标题布局 } } //title.xml如下 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dip" android:text="正在运行,请稍等" /> </LinearLayout> 2 为窗口添加进度条,可用于提示用户程序在运行 //MainActivity如下 //注意在布局文件中: style="@android:style/Widget.ProgressBar.Inverse" //表示使用系统自带的进度条样式 this.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);//相当于告诉系统:我要使用带进度条的窗口布局 setContentView(R.layout.main); this.getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, R.layout.progressbar);//添加窗口进度条布局 setProgressBarIndeterminateVisibility(true); //progressbar.xml如下 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ProgressBar android:id="@+id/progressBar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" style="@android:style/Widget.ProgressBar.Inverse" /> </LinearLayout> 3 为窗口的左上角添加一个图标 //MainActivity如下 requestWindowFeature(Window.FEATURE_LEFT_ICON); setContentView(R.layout.main); this.getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.ic_launcher); 4 窗口全屏显示 //MainActivity如下 requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);