0

I have made two alert dialogs for my application but they are behaving in different ways.

Here is the code for dialog which is behaving as desired.

    LayoutInflater inflater = getLayoutInflater();
    View SinglePlayerLayout = inflater.inflate(R.layout.layout_single_player_options, null);
    AlertDialog.Builder alertD = new AlertDialog.Builder(this);
    final AlertDialog dialog = alertD.create();
    dialog.getWindow().setBackgroundDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.alertbackground));
    dialog.setCancelable(true);
    dialog.setView(SinglePlayerLayout);

The Xml file for this

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/alertbackground">

alertbackground drawable is

<?xml version="1.0" encoding="utf-8"?>

<solid
    android:color="#424a53f7">
    </solid>
<stroke
    android:width="5dp"
    android:color="#000000">
    </stroke>
</shape>

This is the desired output

Now here is the code which is not working as expected

            LayoutInflater inflater= getLayoutInflater();
        View ResultAlertBox = inflater.inflate(R.layout.layout_game_result_2p_same_device, null);
        ResultAlertBox.setBackgroundResource(R.drawable.alertbackground);

        AlertDialog.Builder alertD = new AlertDialog.Builder(this);
        final AlertDialog alertDialog = alertD.create();
        alertDialog.setView(ResultAlertBox);
        alertDialog.setCancelable(false);
        alertDialog.getWindow().setBackgroundDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.alertbackground));

Xml file for this dialog is

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/alertbackground">

alertdialog drawable is common to both but the output shown is

Behind the alert dialog there is a GridView with nine image views on it and above the grid is a relative layout.

Please explain the different behaviours of the same code.

Saumik Bhattacharya
  • 891
  • 1
  • 12
  • 28
penguin2048
  • 1,303
  • 13
  • 25

0 Answers0