Android: How to create a dialog with a scroll list?

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

It will show you how to create a custom dialog, but not how to customize the title!

Basically my title is too long and I want it to scroll (like a text image) or still have a "highlight" effect, which I think is called.

Or, if I can't scroll through it, give it more room to wrap on more lines!

Any ideas, I dont really hope this is not on android.dev :-(

+2


source to share


3 answers


A custom window (and therefore a dialog) can be made by requesting the CUSTOM_TITLE function, which must be executed 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 usually contain anything you want. To control the selection text. for example 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 limitations, using the highlight function selects the text view to be focused, and it will only scroll when it is focused (initially it should be).

+6


source


You can make the dialog a multi-line title:



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

      

+7


source


I believe RuslanK's combination (for getting the TextView) Thorstenvv (for scrolling the TextView) is responsible for the best practice.

0


source







All Articles