I have an AlertDialog
that I set a custom view to. In Android Studio's layout preview it shows what I expect the layout to look like:
However when the app runs on my Nexus 6P it looks like this (Note the extra space at the top, that is what I do not want):
As suggested here I tried changing how the layout was set to:
alertDialog2.setView(view2,0,0,0,0);
alertDialog2.show();
However this did not solve my problem. Any suggestions for how to accomplish this?
XML Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:text="Suggest improvements or changes, or report bugs."
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:id="@+id/textView5"
android:textColor="@color/Black"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="45dp">
<EditText
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/email_feedback_text"
android:layout_marginLeft="125dp"
android:layout_width="250dp"
android:layout_alignParentBottom="false"
android:layout_marginRight="5dp" />
<TextView
android:text="E-mail*:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:id="@+id/textV5"
android:textColor="@color/Black"
android:layout_alignParentLeft="true"
android:layout_marginLeft="30dp" />
</RelativeLayout>
</RelativeLayout>
Java:
AlertDialog.Builder alertDialogBuilderComplete = new AlertDialog.Builder(
MainActivity.this);
alertDialogBuilderComplete.setCancelable(false);
alertDialogBuilderComplete.setTitle("Submit Feedback"); //Set the title of the box
alertDialogBuilderComplete.setMessage("");
alertDialogBuilderComplete.setNegativeButton("Submit",null);
alertDialogBuilderComplete.setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel(); //when they click dismiss we will dismiss the box
}
});
alertDialog2 = alertDialogBuilderComplete.create(); //create the box
alertDialog2.setOnShowListener(new DialogInterface.OnShowListener(){
@Override
public void onShow(DialogInterface dialog) {
Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEGATIVE);
button.setOnClickListener(new View.OnClickListener() {
}
});
}
});
alertDialog2.setView(view2,0,0,0,0);
alertDialog2.show();