Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PopupWindow TouchInterceptor not working

I'm trying to test the PopupWindow class. I've created this method to show the popup:

    public void showPopup(){
            LayoutInflater layoutInflater   = (LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);  
            View popupView = layoutInflater.inflate(R.layout.popup, null);
            final PopupWindow popup = new PopupWindow(popupView, 
                       LayoutParams.WRAP_CONTENT,  
                         LayoutParams.WRAP_CONTENT);  
            popup.setOutsideTouchable(true);
            popup.setTouchable(true);
            popup.setTouchInterceptor(new OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    Log.d("POPUP", event.toString());
                    if(event.getAction() == MotionEvent.ACTION_OUTSIDE){
                        popup.dismiss();
                        return true;
                    }
                    return true;
                }
            });
            popup.showAtLocation(findViewById(R.id.main), Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 200);
}

The popup is showing correctly,by the way it seems that the Touch Interceptor don't work at all: I don't get any log information and of course the popup is not dismissing if pressing outside of it.

Is there some further property I have to set in the popup or in the Activity which host it?

like image 620
Noya Avatar asked Dec 27 '22 07:12

Noya


1 Answers

 pw.setBackgroundDrawable (new BitmapDrawable());
 pw.setFocusable(false);
 pw.setOutsideTouchable(true); 

use this code hope this is helpful

like image 85
Karthi Avatar answered Jan 08 '23 00:01

Karthi