可以通過請求視窗功能CUSTOM_TITLE來完成Customizig視窗(以及對話框)的标題,這必須在setContentView之前完成.
是以,在您的Dialog / Activity子類onCreate()中,調用以下代碼:
super.onCreate(savedInstance);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); //
然後,在您的setContentView之後,執行以下操作:
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title); //
布局通常可以包含您想要的任何内容.
用于字幕文本控件.例如做這個:
布局/ custom_title.xml:
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
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"
>
由于選取框功能的某些限制,必須使文本視圖可聚焦,并且隻有在聚焦時才滾動(最初應該是滾動的).