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