Android UI缺省的標題欄由android:label 定義,顯示在屏幕左上角,Android允許Activity自定義標題欄,使用自定義Layout重新設置標題欄,比如實現Windows Mobile 風格的標題欄。
App->Activity->Custom Title 重新將Activity標題欄定義為左右兩個文本框,其Layout定義R.layout.custom_title_1如下
[html]
<RelativeLayout
xmlns:android=”http://schemas.android.com/apk/res/android”
android:id=”@+id/screen”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical”>
<TextView android:id=”@+id/left_text”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignParentLeft=”true”
android:text=”@string/custom_title_left” />
<TextView android:id=”@+id/right_text”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignParentRight=”true”
android:text=”@string/custom_title_right” />
</RelativeLayout>
<RelativeLayout
xmlns:android=”http://schemas.android.com/apk/res/android”
android:id=”@+id/screen”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:orientation=”vertical”>
<TextView android:id=”@+id/left_text”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignParentLeft=”true”
android:text=”@string/custom_title_left” />
<TextView android:id=”@+id/right_text”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_alignParentRight=”true”
android:text=”@string/custom_title_right” />
</RelativeLayout>
為一左一右兩個文本框。
於每個Activity對應的除瞭使用由setContentView設置的Content View之外,還有一個Windows類對象,Windows 類對象用於控制標題欄,可以允許自定義標題欄或是不顯示標題欄。
Windows 定義瞭一些Feature,允許開發人員做些定制:自定義標題欄對應的Feature ID為Window.FEATURE_CUSTOM_TITLE
[java]
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.custom_title);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_1);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.custom_title);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_1);
作者:mapdigit