設(shè)置為true后點(diǎn)擊外部還是會(huì)被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的解釋來看师抄,當(dāng)focusable=false時(shí),設(shè)置setOutsideTouchable才有意義湖蜕。那么設(shè)置了focusable=true時(shí)逻卖,就沒有意義,因?yàn)閒ocusable=true會(huì)拿走焦點(diǎn)事件昭抒,outside拿不到焦點(diǎn)评也,則的outside的touch就無用處了。
那如何實(shí)現(xiàn)既設(shè)置focusable=true戈鲁,也要外部(outside)點(diǎn)擊不被dismiss呢仇参?
var isForceDismiss = false
override fun dismiss() {
if (isForceDismiss) {
super.dismiss()
isForceDismiss = true
}
}
改寫popupwindow的dismiss方法,做個(gè)邏輯判斷即可婆殿。