I have created a layout, Inflated it and then assigned it to an AlertDialog. Everything is fine but I can't figure out why white spaces are showing around my AlertDialog.
Layout Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:background="@drawable/dialog_backgrounds">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Player Name"
android:id="@+id/tvPlayerName"
android:textSize="24sp"
android:textIsSelectable="false"
android:textColor="#FFFFFF"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text=""
android:ems="10"
android:id="@+id/etPlayerName"
android:gravity="center"
android:textSize="24sp"
android:textColor="#FFFFFF"
android:background="@drawable/hintborder"
android:padding="4dp"
android:maxLength="5"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Android Java Code:
View nameDialogView = View.inflate(MainActivity.this, R.layout.player_name_dialog, null);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
final AlertDialog dialog = builder.create();
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
dialog.setView(nameDialogView);
dialog.show();
Background image is in png and nine-patch
Result i am getting:
Please guide me what is wrong here or any limitations. Thanks.
I changed AlertDialog to Simple Dialog and added few lines that solved problem.
final Dialog dialog = new Dialog(MainActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(nameDialogView);
dialog.show();
dialog.getWindow().getDecorView().setBackgroundResource(android.R.color.transparent);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With