Here is my xml file for my dialog
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/main"
android:paddingTop="23dp"
android:background="@android:color/white">
<ImageView
android:id="@+id/officer"
android:layout_width="47dp"
android:layout_height="47dp"
android:layout_marginLeft="24dp"
android:background="@drawable/officerman"/>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Are you sure you want\nto sign out?"
android:textSize="15.5dp"
android:textColor="#1C86FF"
android:layout_marginTop="4dp"
android:lineSpacingExtra="2dp"
android:layout_marginLeft="84dp"/>
<LinearLayout
android:layout_marginTop="20dp"
android:layout_width="264dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1"
android:layout_below="@id/officer">
<Button
android:id="@+id/yes"
android:layout_width="wrap_content"
android:layout_weight="0.5"
android:layout_height="42dp"
android:background="#1C86FF"
android:text="Yes"
android:textAllCaps="false"
android:textSize="15dp"
android:textColor="@android:color/white"/>
<Button
android:id="@+id/no"
android:layout_width="wrap_content"
android:layout_weight="0.5"
android:layout_height="42dp"
android:background="#0078FF"
android:textSize="15dp"
android:textColor="@android:color/white"
android:textAllCaps="false"
android:text="No"/>
</LinearLayout>
</RelativeLayout>
Here is my java code
AlertDialog.Builder build = new AlertDialog.Builder(Login.this);
View lview = getLayoutInflater().inflate(R.layout.dialog_leave,null);
build.setView(lview);
AlertDialog dialog = build.create();
dialog.show();
The alertdialog
size isn't wrapping to my content no matter what I try. It ends up like this. It adds extended space to the right to get it to a certain size.
I have tried using getWindow.setLayout(width,height)
in pixels, but that is too much of a pain, there must be a better way of doing it.
I tried getWindow.setLayout(Relative.LayoutParams.WRAP_CONTENT, ...)
also, and the same thing still happens.
I have also tried using popupwindow
. What is the easy fix to this issue?