Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize FastScroll alert dialog

Tags:

android

I want to use FastScroll for my history list and use dates for sections, but alert dialog (that shows letters in contacts) does not stretch to fit text's size (i want to show there month and day).

How can I resize it?

like image 200
Denis Palnitsky Avatar asked Nov 06 '22 09:11

Denis Palnitsky


1 Answers

Could it be something as simple as using setView in the AlertDialog class? (Along with some edits to the .xml). First, I took info on setView from here.

public void setView (View view, int viewSpacingLeft, int viewSpacingTop, int viewSpacingRight, int viewSpacingBottom)

Set the view to display in that dialog, specifying the spacing to appear around that view.    
Parameters:
view    The view to show in the content area of the dialog
viewSpacingLeft Extra space to appear to the left of view
viewSpacingTop  Extra space to appear above view
viewSpacingRight    Extra space to appear to the right of view
viewSpacingBottom   Extra space to appear below view

And here's some the SDK's sample code (AlertDialogSamples.java) which uses setView.

case DIALOG_TEXT_ENTRY:
            // This example shows how to add a custom layout to an AlertDialog
            LayoutInflater factory = LayoutInflater.from(this);
            final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null);
            return new AlertDialog.Builder(AlertDialogSamples.this)
                .setIcon(R.drawable.alert_dialog_icon)
                .setTitle(R.string.alert_dialog_text_entry)
                .setView(textEntryView)
                .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked OK so do some stuff */
                    }
                })
                .setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked cancel so do some stuff */
                    }
                })
                .create();
        }
        return null;

And finally, some of the xml file looks like it adds margins around the text (alert_dialog_text_entry.xml).

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <TextView 
        android:id="@+id/username_view"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_marginLeft="20dip"
        android:layout_marginRight="20dip"
        android:text="@string/alert_dialog_username"
        android:gravity="left"
        android:textAppearance="?android:attr/textAppearanceMedium" />

Hope it helps.

like image 104
gary Avatar answered Nov 15 '22 09:11

gary