0

I have a small problem with the popup window functionality.I would like to close it when the user clicks outside of the window.I have read a lots of atricle on stackoverflow, but not a single articles helped me. What I have tried is, I have tried to popupwindow.setBackgroundDrawable(null); which is not worked for me.

 LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.popupmenu_layout, (ViewGroup) findViewById(R.id.popuplinearlayout));
    pw = new PopupWindow(layout, 300, 300, true);
    pw.showAtLocation(layout, Gravity.CENTER, 0, 0);
    pw.setBackgroundDrawable(null);
    pw.setOutsideTouchable(true);
    //Todo remove popup window when outside is touched...    

If you know a good article what may help me I would appreciate it.It is posible this features is not working in emulator ? I have only emulator right now.(android 4.4.2)

user2629828
  • 685
  • 1
  • 8
  • 13

3 Answers3

1

And if Marcin's constructor is deprecated, use

pw.setBackgroundDrawable(new BitmapDrawable(getResources(),""));
yildirimyigit
  • 3,013
  • 4
  • 25
  • 35
0

Instead of

pw.setBackgroundDrawable(null);

do

pw.setBackgroundDrawable(new BitmapDrawable());
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
0

use pw.setBackgroundDrawable(new BitmapDrawable(getResources(),""));

Set window background transtarent.

pw.getBackground().setAlpha(0);

Sagar Pilkhwal
  • 3,998
  • 2
  • 25
  • 77