Skip to content Skip to sidebar Skip to footer

Alertdialog - Gap Between Custom View And Title/buttons

I use a custom view for an AlertDialog. In the emulator, there is some space above and below the customeView. If I set a title and buttons for the AlertDialog, I can see the gap be

Solution 1:

Instead of using AlertDialog try using Dialog instead like so:

var dialog = new Dialog(this);
dialog.SetTitle("Hey there");

dialog.SetContentView(Resource.Layout.myDialog);
dialog.Show();

This gives me the a dialog with no gap in the bottom.

Dialog with no bottom gap

You could also leave the title out and fill the entire Dialog with your custom view.

var dialog = new Dialog(this);
dialog.RequestWindowFeature((int)WindowFeatures.NoTitle);

dialog.SetContentView(Resource.Layout.myDialog);
dialog.Show();

And use this layout:

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="wrap_content"android:background="#FFFFFF"><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:background="#000000"><TextViewandroid:text="Hey there"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_margin="10dp"style="@android:style/TextAppearance.DialogWindowTitle" /></LinearLayout><TextViewandroid:id="@+id/DialogText"android:text="This is my custom view. Blur Blur Blur"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"android:layout_height="wrap_content"android:layout_width="wrap_content" /><EditTextandroid:id="@+id/EnterPhone"android:inputType="phone"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"android:hint="enter your number" /></LinearLayout>

Dialog with no gaps

Post a Comment for "Alertdialog - Gap Between Custom View And Title/buttons"