Android中requestWindowFeature()的應用

Android開發中經常會在setContentView(R.layout.XXX); 前設置requestWindowFeature(XXXX)。

他的意思是需要軟件全屏顯示、自定義標題(使用按鈕等控件)和其他的需求

首先介紹一個重要方法那就是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.FEATURE_CUSTOM_TITLE詳解

Java代碼  收藏代碼

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

這是因爲沒有設置Featrue

在上面代碼後加:getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.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/ic_launcher"  
        />  
  
    <TextView  
        android:id="@+id/text"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_alignParentLeft="true"  
        android:textColor="#000000"  
        android:text="FEATURE_CUSTOM_TITLE" />  
  
</LinearLayout>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章