1

I am using Android 2.3

I have an alertdialog in my app. Here the code:

final CharSequence[] items = { "Entfernen", "Auswählen",
                    "Editieren", "Zurücksetzen", "Abbrechen" };

            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(productName);
            builder.setItems(items, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {...}

I have a strange problem: The Dialog always fills the whole width of my display. And therefore the text of the selectors is very large. How can I limit this? Either textsize or width of this dialog...

tobias
  • 2,322
  • 3
  • 33
  • 53
  • 1
    http://stackoverflow.com/questions/4406804/how-to-control-the-width-and-height-of-default-alert-dialog-in-android the third answer is what you are looking for, I believe. – Ben Roby G Sep 13 '11 at 21:05

1 Answers1

0

You can call the following method of your alert dialog to inflate a custom xml into your alert dialog.

dialog.setContentView(R.layout.alert_dialog);

After calling this, you would need to set TextView/ImageView variables, just like how you would with activities.

For a better example, check out Android API Docs. http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog

Ye Myat Min
  • 1,429
  • 2
  • 17
  • 29
  • I know how to create custom dialogs. But it seems strange for me, that the default alertdialog is streched to whole width of screen. – tobias Sep 13 '11 at 23:05
  • It'd be great if you could show me some screenshots and code snippets of what you are doing. – Ye Myat Min Sep 14 '11 at 17:40
  • The code you can see in my post. I simply show the dialog. But the entries textsize is strangly very large – tobias Sep 14 '11 at 18:38