Android 應用程序窗體顯示狀態操作

我們在開發程序是經常會需要軟件全屏顯示、自定義標題(使用按鈕等控件)和其他的需求,今天這一講就是如何控制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:標題欄右側的圖標

 

二、詳解

默認顯示狀態

Android 應用程序窗體顯示狀態操作

圖1默認

1.FEATURE_CUSTOM_TITLE詳解

this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.main);

 

Android 應用程序窗體顯示狀態操作

圖2 無標題

 

這是因為沒設置Featrue

在上面代碼后加:getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title);    

Android 應用程序窗體顯示狀態操作    

圖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詳解

表示一個進程正在運行

Android 應用程序窗體顯示狀態操作

                圖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詳解

左側顯示圖標

Android 應用程序窗體顯示狀態操作

圖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);

 Android 應用程序窗體顯示狀態操作

圖6全屏顯示

轉自:http://www.cnblogs.com/salam/archive/2010/11/30/1892143.html


 本文由用戶 xia198507 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!