设置为true后点击外部还是会被dismiss掉,这是为什么?
/**
* <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;
}
从官方api的解释来看,当focusable=false时,设置setOutsideTouchable才有意义。那么设置了focusable=true时,就没有意义,因为focusable=true会拿走焦点事件,outside拿不到焦点,则的outside的touch就无用处了。
那如何实现既设置focusable=true,也要外部(outside)点击不被dismiss呢?
var isForceDismiss = false
override fun dismiss() {
if (isForceDismiss) {
super.dismiss()
isForceDismiss = true
}
}
改写popupwindow的dismiss方法,做个逻辑判断即可。