Customizig窗口(也因此而對話)的標題可以通過請求窗口功能CUSTOM_TITLE來完成,必須。在對話框/活動的setContentView之前完成
,這樣子類的onCreate(),請撥打以下:
super.onCreate(savedInstance);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); // <- insert this
然後,後你的setContentView,這樣做:
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title); // <- insert this
佈局通常可以包含任何你想要的。 對於選取框文本控件。例如做到這一點:
佈局/ custom_title.xml:
<FrameLayout android:id="@+id/FrameLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView android:id="@+id/caption_text"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="This is a very very long text that will not fit into a caption regularly, so it will be displayed using marquee..."
android:lines="1"
android:focusable="true"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:marqueeRepeatLimit="marquee_forever"
android:ellipsize="marquee"
></TextView>
</FrameLayout>
由於與字幕功能的一些約束,文本視圖要作出可成爲焦點,它只會滾動聚焦時(它最初應該是)。
謝謝 - 我會稍後再試 – Blundell 2010-09-09 14:44:47
如果我必須使用setTitle(myString);在我的活動? – Kishore 2014-01-02 07:57:33