1、点击PopupWindow 外部区域时,PopupWindow消失

popMenu = new PopupWindow(getApplicationContext());
popMenu.setWidth(LayoutParams.MATCH_PARENT); popMenu.setHeight(LayoutParams.MATCH_PARENT); popMenu.setBackgroundDrawable(new BitmapDrawable()); popMenu.setFocusable(true);
popMenu.setOutsideTouchable(true);

这里使用了 setOutsideTouchable 属性,具体可以去参考 developer文档。

使用PopupWindow注意事项:必须设置PopupWindow的backgroundDrawable,否则会出现各种意想不到的bug。

2、点击PopupWindow 自身时(非按钮控件时),PopupWindow消失

解决办法:给 PopupWindow的 contentView 注册一个点击事件

view.setOnClickListener(new OnClickListener() {

			@Override
public void onClick(View v) {
if(popMenu.isShowing()){
dismiss();
}
}
}); popMenu.setContentView(view); popMenu.showAtLocation(v, Gravity.BOTTOM, 0, 0);
// popMenu.setAnimationStyle(R.style.popwin_anim_style); popMenu.update();

  

  

Android PopupWindow 点击消失解决办法的更多相关文章

  1. android adb devices offline的解决办法

    在做Android开发时经常出现android adb devices offline,解决办法如下: 1 重启adb服务 adb kill-server adb start-server linux ...

  2. android studio 错误汇总以及解决办法

    android studio 错误汇总以及解决办法  参考 https://www.jianshu.com/p/7c7de6562231 问题1. Error:Execution failed for ...

  3. 【转】Android出现“Read-only file system”解决办法

    原文网址:http://www.111cn.net/sj/android/44496.htm 下面介绍一篇Android出现“Read-only file system”解决办法 有碰到这类问题的朋友 ...

  4. 【转】Ubuntu 上编译Android出现cannot find -lstdc++解决办法

    [转]Ubuntu 上编译Android出现cannot find -lstdc++解决办法 在Ubuntu 12.04 x86_64机器上编译Android出现下面错误,是因为找不到32bit的li ...

  5. (转载)Android出现“Read-only file system”解决办法

    下面介绍一篇Android出现“Read-only file system”解决办法 有碰到这类问题的朋友可参考参考.   Android-出现Read-only file system的解决方法 输 ...

  6. Ubuntu中Android SDK Manager无法更新解决办法

    Ubuntu中Android SDK Manager无法更新解决办法http://hi.baidu.com/petercao2008/item/d7a64441f04668e81e19bc1a

  7. Xamarin Android SDK无法更新的解决办法

    Xamarin Android SDK无法更新的解决办法   Xamarin Android SDK无法更新的解决办法,更新时候,提示警告信息:A folder failed to be moved. ...

  8. 1.Android常见异常:android.view.WindowLeaked 分析以及解决办法

    在项目中遇到WindowManager: Activity  has leaked window问题,其实在stackoverflow.com可以找到详细答案:http://stackoverflow ...

  9. Toolbar 和 CollapsingToolbarLayout一起使用时menu item无点击反应解决办法

    昨天一直在琢磨为什么Toolbar和CollapsingToolbarLayout一起使用时menu item无点击放应的原因,后来在stackoverflow上一条回答,说可能是Toolbar的背景 ...

随机推荐

  1. Table of Contents - Redis

    Getting Started 安装配置环境 Redis 命令 Keys Strings Lists Hashs Sets Sorted Sets Transactions Connection Se ...

  2. Part 1 What is SSMS?

    note that,SSMS is a client tool and not the server by itself,it is a developer machines connects to ...

  3. 发布ASP.NET网站到IIS

    1.         在Web项目中点击发布网站,如图1所示 图1 2.         选择要发布的路径——>“确定”,如果项目显示发布成功就可以了.如图2所示 图2 3.         打 ...

  4. redistribute and Suboptimal routing

    重分发和次优路由 基础环境 拓扑: 分别配置好基本的环境,包含ip地址,路由协议的启用,得到他们的路由表分别为 R1: R2: R3: R4: 1.      在R1上将eigrp和OSPF进行双向重 ...

  5. 高仿百度传课应用客户端源码iOS版

    高仿百度传课iOS版,版本号:2.4.1.2 运行环境:xcode6.3  ios8.3 (再往上系统没有测试) 转载请注明出处,不可用于商业用途及不合法用途. 如果你觉得不错,欢迎  star  哦 ...

  6. 初识 Jenkins

    Jenkins: Jenkins 是一款获奖的跨平台持续集成和持续交付软件,可以大大提高生产力.Jenkins 用以构建和测试软件项目,帮助开发者更容易的实现项目变更的持续集成,帮助用户更容易的获取最 ...

  7. (转).NET Memory Profiler 使用简介

    1         简介 .Net Memory Profiler(以下简称Profiler):专门针对于.NET程序,功能最全的内存分析工具,最大的特点是具有内存动态分析(Automatic Mem ...

  8. BigInteger大数家法源代码及分析

    我们可以把一个很大很长的数分成多个短小的数,然后保存在一个数组中,大数之间的四则运算及其它运算都是通过数组完成.JDK就是这么实现的.JDK的BigInteger类里用一个int数组来保存数据: /* ...

  9. 杭电ACM2097--Sky数

    这题思路很简单,把10,12,16进制数都按位相加,然后进行比较即可. http://acm.hdu.edu.cn/showproblem.php?pid=2097 <span style=&q ...

  10. 4.Servlet_Form表单处理

    1.建项目"3Servlet_Form",src下建包“com.amaker.servlet”,web-root下建Register.html <!DOCTYPE html& ...