Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove white space or color around AlertDialog

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:

enter image description here

Please guide me what is wrong here or any limitations. Thanks.

like image 574
Mian.Ammar Avatar asked Jan 09 '23 22:01

Mian.Ammar


1 Answers

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);
like image 189
Mian.Ammar Avatar answered Jan 11 '23 12:01

Mian.Ammar