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

更多相关文章

  1. Android(安卓)menu菜单items间隔设置
  2. Android(安卓)View onMeasure 方法
  3. Android之手机壁纸的改变
  4. [Android] 环境优化配置Android(安卓)Studio发展NDK
  5. android使用CheckedTextView搭配listview完成选择列表
  6. Android(安卓)build.gradle 中 使用 buildConfigField 动态设置
  7. android 设置textview边框以及点击效果
  8. Android(安卓)手机bluetooth 名字的设置
  9. Android连续点击两次返回键退出App

随机推荐

  1. Android 自定义View 使用VelocityTracker
  2. android中使用properties文件配置
  3. Android Studio 本地化配置gradle的build
  4. AndEngine引擎学习之环境配置以及示例修
  5. 蓝牙BLE开发基础教程 android5.0 蓝牙4.0
  6. android 按钮倒计时读秒
  7. Android 浅谈相机研发
  8. 加速 Android 依赖下载
  9. Android 对话框(Dialog)【大全】
  10. Android 开发环境准备(Ubuntu)