After setting it to true, clicking outside will still be dismissed. Why?
/**
* <p>Controls whether the pop-up will be informed of touch events outside
* of its window. This only makes sense for pop-ups that are touchable
* but not focusable, which means touches outside of the window will
* be delivered to the window behind. The default is false.</p>
*
* <p>If the popup is showing, calling this method will take effect only
* the next time the popup is shown or through a manual call to one of
* the {@link #update()} methods.</p>
*
* @param touchable true if the popup should receive outside
* touch events, false otherwise
*
* @see #isOutsideTouchable()
* @see #isShowing()
* @see #update()
*/
public void setOutsideTouchable(boolean touchable) {
mOutsideTouchable = touchable;
}
From the explanation of the official api, when focusable=false, it makes sense to set setOutsideTouchable. Then when focusable=true is set, it is meaningless, because focusable=true will take away the focus event, and if the outside cannot get the focus, the outside touch will be useless.
So how to set focusable=true, but also to prevent external (outside) clicks from being dismissed?
var isForceDismiss = false
override fun dismiss() {
if (isForceDismiss) {
super.dismiss()
isForceDismiss = true
}
}
Rewrite the dismiss method of popupwindow and make a logical judgment.