2010-08-26 87 views
2

好了,所以我读过的自定义对话框的解释和DEV网站上 http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialogAndroid:如何使用滚动标题创建对话框?

它展示的你如何做一个自定义对话框,但不知道如何自定义标题!

基本上我的标题太长了,我希望它滚动(如textview)或更好的仍然有一个'选取框'的效果,我认为它被称为。

或者如果我不能让它滚动,给它更多的空间来包装更多的线!

任何想法,我不抱太大的希望,因为它不是在android.dev :-(

回答

6

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> 

由于与字幕功能的一些约束,文本视图要作出可成为焦点,它只会滚动聚焦时(它最初应该是)。

+0

谢谢 - 我会稍后再试 – Blundell 2010-09-09 14:44:47

+0

如果我必须使用setTitle(myString);在我的活动? – Kishore 2014-01-02 07:57:33

7

你可以让对话框的标题多:

TextView title = (TextView) dialog.findViewById(android.R.id.title); 
title.setSingleLine(false); 
+0

我认为这个答案比在没有必要的时候继承对话要好一些。 – 2014-11-05 11:28:03

0

我认为(用于获取的TextView)RuslanK的组合Thorstenvv的(制作的TextView滚动)的回答是最好的做法。