1

I have some problem with AlertDialog when I'm trying to blur his Background with Bitmap class.

For some reason, when I'm calling pop up , it's blurring only part of screen. As you can see in the attached image, the layout of dialog not filling the screen. When I'm blurring other layouts, for example fragments , it's working good .

public void errorPopup(String error) {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mActivity);
    LayoutInflater inflater = mActivity.getLayoutInflater();
    View dialogView = inflater.inflate(R.layout.popup_layout, null);
    dialogBuilder.setView(dialogView);

    Bitmap map = new BlurUtils().takeScreenShot(mActivity);
    Bitmap fast = new BlurUtils().fastblur(map, 50);
    Drawable drawable = new BitmapDrawable(mResources, fast);
    dialogView.setBackground(drawable);
    final AlertDialog alertDialog = dialogBuilder.create();
    alertDialog.show();

    TextView tvErrorMessage = alertDialog.findViewById(R.id.tvErrorMessage);
    tvErrorMessage.setText(error);

    Button btnAccept = alertDialog.findViewById(R.id.btnAccept);
    btnAccept.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            alertDialog.cancel();
        }
    });
}

Dialog layout

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/popup_root_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_centerInParent="true"
        android:background="@drawable/popup_background">

        <TextView
            android:id="@+id/tvErrorMessage"
            android:layout_width="250dp"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="@string/no_error_message"
            android:textAlignment="center" />

        <Button
            android:id="@+id/btnAccept"
            android:layout_width="150dp"
            android:layout_height="40dp"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:background="@null"
            android:stateListAnimator="@null"
            android:text="@string/try_again" />
    </RelativeLayout>
</RelativeLayout

enter image description here

Rahul Gaur
  • 1,661
  • 1
  • 13
  • 29
Michael
  • 429
  • 5
  • 22

2 Answers2

0

Add complete code Michael, only then I'll be able to help you with that. Because you giving "fixed height and width of layout that you want to blur and fit", for that you need to set height and width as "match_parent".

  • But it's a complete code mate. And as you can see, I'm already using MATCH_PARENT for the root layout. – Michael Feb 08 '20 at 17:18
0

Ok I fixed it :

AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mActivity, R.style.Theme_AppCompat_Light_NoActionBar);
Michael
  • 429
  • 5
  • 22