Android(安卓)NoteX Q9: PopupWindow setOutsideTouchable 失效?
16lz
2021-12-04
设置为true后点击外部还是会被dismiss掉,这是为什么?
/** * 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.
* * 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.
* * @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 = falseoverride fun dismiss() { if (isForceDismiss) { super.dismiss()isForceDismiss = true }}
改写popupwindow的dismiss方法,做个逻辑判断即可。
更多相关文章
- Android(安卓)menu菜单items间隔设置
- Android(安卓)View onMeasure 方法
- Android之手机壁纸的改变
- [Android] 环境优化配置Android(安卓)Studio发展NDK
- android使用CheckedTextView搭配listview完成选择列表
- Android(安卓)build.gradle 中 使用 buildConfigField 动态设置
- android 设置textview边框以及点击效果
- Android(安卓)手机bluetooth 名字的设置
- Android连续点击两次返回键退出App