5

I want to dark the background after popup window open and restore everything like before after dismissing. I have searched google and seen some tutorial also. But I don't be able to understand how it is possible. Here's My Java Code:

public void displayPopupWindow() {
    View layout = getLayoutInflater().inflate(R.layout.popup,null);
    final PopupWindow popup = new PopupWindow(this);
    popup.setContentView(layout);
    popup.setOutsideTouchable(true);
    popup.setFocusable(true);
    popup.setWidth(400);
    popup.setHeight(580);
    popup.showAtLocation(layout, Gravity.CENTER, 0, 0);
    popup.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    Button button = (Button) layout.findViewById(R.id.button);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View layout) {
            popup.dismiss();
        }
    });

}

Here my popup xml code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/colorPrimary"
android:id="@+id/popup"
>
Various views and button
</RelativeLayout>

What should I do now?

Bill Redoy
  • 91
  • 2
  • 8

1 Answers1

-1

you can try this out

replace

popup.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

with this in your code

popup.setBackgroundDrawable(new ColorDrawable(Color.BLACK));

you can change any background as per choice.

Apoorv Mehrotra
  • 607
  • 5
  • 13