轉: http://www.cnblogs.com/salam/archive/2010/11/30/1892143.html
我們在開發程式是經常會需要軟體全螢幕顯示、自訂標題(使用按鈕等控制項)和其他的需求,今天這一講就是如何控制Android應用程式的表單顯示.
首先介紹一個重要方法那就是requestWindowFeature(featrueId),它的功能是啟用表單的擴充特性。參數是Window類中定義的常量。
一、枚舉常量
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:標題列右側的表徵圖
二、詳解
預設顯示狀態
圖1預設
1.FEATURE_CUSTOM_TITLE詳解
this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
圖2 無標題
這是因為沒設定Featrue
在上面代碼後加:getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
圖3自訂標題
自訂標題完成,它是一個xml檔案布局
title.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon"/>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="文本" />
</LinearLayout>
3.FEATURE_INDETERMINATE_PROGRESS詳解
表示一個進程正在運行
圖4標題進度條顯示
實現代碼
1.progress.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
style="?android:attr/progressBarStyleSmallTitle">
</ProgressBar>
</LinearLayout>
2.Java代碼
this.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, R.layout.progress);
setProgressBarIndeterminateVisibility(true);
3.FEATURE_LEFT_ICON詳解
左側顯示表徵圖
圖5
實現代碼
this.requestWindowFeature(Window.FEATURE_LEFT_ICON);
setContentView(R.layout.main);
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.icon);
4.FEATURE_NO_TITLE詳解
可用於全螢幕顯示
實現代碼
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
圖6全螢幕顯示
我們在開發程式是經常會需要軟體全螢幕顯示、自訂標題(使用按鈕等控制項)和其他的需求,今天這一講就是如何控制Android應用程式的表單顯示.
首先介紹一個重要方法那就是requestWindowFeature(featrueId),它的功能是啟用表單的擴充特性。參數是Window類中定義的常量。
一、枚舉常量
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:標題列右側的表徵圖
二、詳解
預設顯示狀態
圖1預設
1.FEATURE_CUSTOM_TITLE詳解
this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
圖2 無標題
這是因為沒設定Featrue
在上面代碼後加:getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);
圖3自訂標題
自訂標題完成,它是一個xml檔案布局
title.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon"/>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="文本" />
</LinearLayout>
3.FEATURE_INDETERMINATE_PROGRESS詳解
表示一個進程正在運行
圖4標題進度條顯示
實現代碼
1.progress.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ProgressBar android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
style="?android:attr/progressBarStyleSmallTitle">
</ProgressBar>
</LinearLayout>
2.Java代碼
this.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_INDETERMINATE_PROGRESS, R.layout.progress);
setProgressBarIndeterminateVisibility(true);
3.FEATURE_LEFT_ICON詳解
左側顯示表徵圖
圖5
實現代碼
this.requestWindowFeature(Window.FEATURE_LEFT_ICON);
setContentView(R.layout.main);
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.icon);
4.FEATURE_NO_TITLE詳解
可用於全螢幕顯示
實現代碼
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
圖6全螢幕顯示