For new search engines , since the creation of new BitmapDrawable now not allowed ( The constructor BitmapDrawable() is deprecated ), so you need to change it to new ShapeDrawable() so that you change:
pw.setBackgroundDrawable(new BitmapDrawable());
To:
pw.setBackgroundDrawable(new ShapeDrawable());
And all the work will be like this:
PopupWindow pw; LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.weight_popup, (ViewGroup)findViewById(R.id.linlay_weight_popup)); pw = new PopupWindow(layout,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT, true); pw.setOutsideTouchable(true); pw.setBackgroundDrawable(new ShapeDrawable()); pw.setTouchInterceptor(new OnTouchListener() { // or whatever you want @Override public boolean onTouch(View v, MotionEvent event) { if(event.getAction() == MotionEvent.ACTION_OUTSIDE) // here I want to close the pw when clicking outside it but at all this is just an example of how it works and you can implement the onTouch() or the onKey() you want { pw.dismiss(); return true; } return false; } }); pw.showAtLocation(layout, Gravity.CENTER, 0, 0);
Muhammed Refaat May 22 '14 at 9:12 a.m. 2014-05-22 09:12
source share