Android Popup Window dismisses when clicked outside

后端 未结 2 401
暗喜
暗喜 2021-01-12 22:59

I was hoping to get an answer to my problem I have at the moment.

I have a class which extends popup window. It works fine except I don\'t want the window to dismis

2条回答
  •  灰色年华
    2021-01-12 23:44

    Ok so fixed in the end.

    First made the main layout which the popup sits on a relative layout. Then placed a full screen blank layout on top which I made invisible and transparent.

    Then show when the popup is shown, set the full screen panel visible with setVisibility(View.VISIBLE); and hide when popup is hidden with setVisibility(View.GONE);

    Also need to return true from an on touch listener for the layout with (To stop touch events passing back to the main layout):

    blocker.setOnTouchListener(new OnTouchListener() { 
    @Override
    public boolean onTouch(View v, MotionEvent event) {
    return true;
    }
    });
    

    And give the popup window the properties:

    setTouchable(true);
    setOutsideTouchable(false);
    

    Cheers

提交回复
热议问题