Android:如何创建带有滚动标题的对话框?

Android: How to create a Dialog with a Scrolling title?(Android:如何创建带有滚动标题的对话框?)
本文介绍了Android:如何创建带有滚动标题的对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

好的,我已经阅读了 And Dev 网站上的自定义对话框说明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 :-(

推荐答案

自定义窗口(以及对话框)标题可以通过请求窗口功能 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.

因此,在您的 Dialog/Activity 子类 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:如何创建带有滚动标题的对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)
cocos2d-android: how to display score(cocos2d-android:如何显示分数)
Converting Flash Animation to Cocos2D(将 Flash 动画转换为 Cocos2D)
Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
Android file copy(安卓文件拷贝)