Android:如何使用滚动标题创建对话框? [英] Android: How to create a Dialog with a Scrolling title?

查看:216
本文介绍了Android:如何使用滚动标题创建对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,所以我已经阅读了And Dev网站上的自定义对话框说明
http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog



它显示如何做一个自定义对话框,但不是如何自定义标题!



基本上我的标题太长,我想要滚动(如textview)或更好还是有一个'b'b
$ b

或者如果我无法使它滚动,给它更多的空间来包装更多的行!



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

解决方案

Customizig窗口(从而也是对话框)的标题可以通过请求窗口功能CUSTOM_TITLE来完成,CUSTOM_TITLE必须在setContentView之前完成。



所以在对话框中/ Activity子类onCreate(),调用如下:

  super.onCreate(savedInstance); 
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); //< - 插入此

然后,之后您的setContentView,do这个:

  setContentView(R.layout.main); 
getWindow()。setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title); //< - 插入此

布局通常可以包含任何您想要的。
对于大理石文本控件。例如这样做:



layout / 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是一个非常长的文本,不适合定期的标题,所以它将显示使用大括号...
android:lines =1
android:focusable =true
android:focusableInTouchMode =true
android:scrollHorizo​​ntally =true
android:marqueeRepeatLimit =marquee_forever
android:ellipsize =marquee
>< / TextView的>
< / FrameLayout>

由于选框功能的某些限制,文本视图必须可对焦,重点关注滚动(最初应该是滚动)。


Ok so I've read the Custom Dialog explanation on the And Dev website http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog

It show's you how to make a custom dialog, but not how to customise the title!

Basically my title is too long and I want it to scroll (like textview) or better still have a 'marquee' effect i think it's called.

Or if I can't make it scroll, give it more space to wrap onto more lines!

Any ideas, I don't hold out much hope as it's not on android.dev :-(

解决方案

Customizig window (and thus also dialog) titles can be done by requesting the window feature CUSTOM_TITLE, which must be done before setContentView.

So in your Dialog / Activity subclasses onCreate(), call the following:

super.onCreate(savedInstance);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); // <- insert this

Then, after your setContentView, do this:

setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title); // <- insert this

The layout can generally contain anything you want. For a marquee text control. e.g. do this:

layout/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>

Due to some constraints with the marquee feature, the text view has to be made focusable and it will only be scrolling when focused (which it initially should be).

这篇关于Android:如何使用滚动标题创建对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆