可以通过请求窗口功能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"
>
由于选取框功能的某些限制,必须使文本视图可聚焦,并且只有在聚焦时才滚动(最初应该是滚动的).