javaandroidpopuppopupwindowandroid-popupwindow

Dim or blur background of popup window


I am able to get the pop up window but the background is transparent also I am able to read the contents of the activity behind it. I want to dim the background so the pop up and the older activity gets differentiated.


Solution

  • You can do it in 2 ways
    1. by adding background color with transparency, to the parent of your popup layout. example:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#cc000000">
    
    <YOUR_POPUP_VIEW
    .... /> 
    </RelativeLayout>
    
    1. WindowManager.LayoutParams layoutParams = getWindow().getAttributes(); layoutParams.dimAmount = #WHAT_EVER_VALUE_YOU_WANT_TO_KEEP; //Generally in between 0.70f to 0.80f getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); getWindow().setAttributes(layoutParams);