Search code examples
androidpopuppopupwindowtouch-event

How to delegate touch events on both popup window and activity android


I have an activity which is having two buttons and a popup window.By click a button popup will display. I want to handle touch events in both popup window and activity. In the below image i want to handle Ok button click with out dismiss the popup widow. At the same time i need dismiss button event as well.

I have tried

popWindow.setTouchable(true); then activity events are not working.

popWindow.setTouchable(false); then popup window events are not working.

Please see the image for reference.

Thanks in advance.

enter image description here


Solution

  • You can achieve this using WindowManager.

    private void popUp(View yourPopUpView,WindowManager.LayoutParams params){
        WindowManager manager = (WindowManager)getSystemService(WINDOW_SERVICE);
        manager.addView(yourPopUpView,params);
    }
    

    remove same view using

    private void removePopUp(View yourPopUpView){
        WindowManager manager = (WindowManager)getSystemService(WINDOW_SERVICE);
        manager.removeView(yourPopUpView);
    }
    

    but don't forget to remove that view onResume of your activity. B'coz it will remain after destroy of your activity also..

    Hope this helps...