標籤:
Android UI預設的標題列由android:label 定義,顯示在螢幕左上方,Android允許Activity自訂標題列,使用自訂Layout重新設定標題列,比如實現Windows Mobile 風格的標題列。
App->Activity->Custom Title 重新將Activity標題列定義為左右兩個文字框,類CustomTitle,其Layout定義R.layout.custom_title_1如下,為一左一右兩個文字框:
<!-- Demonstrates how to use a custom title. See corresponding Java code com.example.android.apis.app.CustomTitle.java. --><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。
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.custom_title); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_1);
這裡可直接通過findViewById擷取到R.layout.custom_title_1中的view。
【起航計劃 006】2015 起航計劃 Android APIDemo的魔鬼步伐 05 App->Activity->Custom Title 自訂標題列