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

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

问题描述

好了,所以我读过的和开发网站上的自定义对话框的解释 http://developer.android.com/guide/topics/ui/dialogs html的#CustomDialog

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!

基本上我的标题太长,我想它滚动(如TextView的),或者更好的是有一个金字招牌效应,我认为这就是所谓的。

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!

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

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

推荐答案

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

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

所以,在对话框/活动的子类的onCreate(),请拨打以下:

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

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

然后,您的setContentView,做到这一点:

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:

布局/ custom_title.xml:

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天全站免登陆