Change background color when a Popup is shown

android, popupwindow

Solution

In your xml file add something like this with width and height as 'match_parent'.

<RelativeLayout
        android:id="@+id/bac_dim_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#C0000000"
        android:visibility="gone" >
</RelativeLayout>

In your activity oncreate

//setting background dim when showing popup
back_dim_layout = (RelativeLayout) findViewById(R.id.bac_dim_layout);

Finally make visible when you show your popupwindow and make its visible gone when you exit popupwindow.

back_dim_layout.setVisibility(View.Visible);
back_dim_layout.setVisibility(View.GONE);

Problem

I want to make the background darker when a `PopupWindow` is shown. Just like Dolphin Browser does like- Before the PopupWindow After the PopupWindow The background color is darker than what it was. So, how can we do this?

Original source