美文网首页Android NoteXAndroid开发学习
Android NoteX Q9: PopupWindow se

Android NoteX Q9: PopupWindow se

作者: 不会飞的小猪 | 来源:发表于2021-05-31 21:36 被阅读0次

设置为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方法,做个逻辑判断即可。

相关文章

网友评论

    本文标题:Android NoteX Q9: PopupWindow se

    本文链接:https://www.haomeiwen.com/subject/nhcisltx.html