Popupwindow大家肯定都特别熟悉了 像一般的提示框的话我们会用Dialog来做 但是随着设计要求的不断提高,App中各式各样的提示框都有,很明显普通的Dialog实现起来就比较吃力了 所以用Popupwindow来实现是最好不过了 ,于是我也自己写了一个popupwindow弹出的一个方法,代码量少简单灵活 先看一下效果图

大致效果就是这样 当然你也可以将layout中的布局换成自己的布局 接下来是代码

  private void ejectPopup() {View parent = ((ViewGroup) this.findViewById(android.R.id.content)).getChildAt(0);View popView = View.inflate(this, R.layout.details_share, null);int width = getResources().getDisplayMetrics().widthPixels;int height = getResources().getDisplayMetrics().heightPixels;
//        int i = height /5*2;popWindow = new PopupWindow(popView, width, ViewGroup.LayoutParams.WRAP_CONTENT);popWindow.setAnimationStyle(R.style.Search_PopupWindowAnimation);popWindow.setFocusable(true);popWindow.setOutsideTouchable(false);// 设置同意在外点击消失ColorDrawable dw = new ColorDrawable(0x30000000);popWindow.setBackgroundDrawable(dw);popWindow.showAtLocation(parent, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);popWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);//被home键挡住//给popup中的按钮做监听WindowManager.LayoutParams lp = getWindow().getAttributes();lp.alpha = (float) 0.7; //0.0-1.0getWindow().setAttributes(lp);popWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {@Overridepublic void onDismiss() {WindowManager.LayoutParams lp = getWindow().getAttributes();lp.alpha = (float) 1; //0.0-1.0getWindow().setAttributes(lp);}});
}

这个就是调用的方法  背景变暗可以通过这段代码来实现

 popWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {@Overridepublic void onDismiss() {WindowManager.LayoutParams lp = getWindow().getAttributes();lp.alpha = (float) 1; //0.0-1.0getWindow().setAttributes(lp);}});

当让也可以让ui妹子给你切一个透明的背景图片

最后是layout中的代码

<?xml version="1.0" encoding="utf-8"?>
<com.zhy.autolayout.AutoLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:orientation="vertical" android:layout_width="match_parent"android:background="#fff"android:layout_height="239dp"><com.zhy.autolayout.AutoLinearLayoutandroid:gravity="center"android:layout_width="match_parent"android:layout_height="51dp"><TextViewandroid:text="请选择分享平台"android:textColor="#29292a"android:textSize="18sp"android:layout_width="wrap_content"android:layout_height="wrap_content" /></com.zhy.autolayout.AutoLinearLayout><TextViewandroid:background="@color/divider_color"android:layout_width="match_parent"android:layout_height="1dp" /><com.zhy.autolayout.AutoLinearLayoutandroid:layout_marginBottom="10dp"android:layout_width="match_parent"android:layout_height="132dp"><com.zhy.autolayout.AutoRelativeLayoutandroid:id="@+id/share_WX"android:layout_marginLeft="13dp"android:layout_width="0dp"android:layout_weight="1"android:layout_height="match_parent"><ImageViewandroid:id="@+id/share_WX_icon"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:layout_centerVertical="true"app:srcCompat="@drawable/wechat" /><TextViewandroid:text="微信"android:layout_marginTop="6dp"android:layout_below="@id/share_WX_icon"android:layout_centerHorizontal="true"android:layout_width="wrap_content"android:layout_height="wrap_content" /></com.zhy.autolayout.AutoRelativeLayout><com.zhy.autolayout.AutoRelativeLayoutandroid:id="@+id/share_WXPYQ"android:layout_width="0dp"android:layout_weight="1"android:layout_height="match_parent"><ImageViewandroid:id="@+id/share_WXPYQ_icon"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:layout_centerVertical="true"app:srcCompat="@drawable/circleoffriends" /><TextViewandroid:text="朋友圈"android:layout_marginTop="6dp"android:layout_below="@id/share_WXPYQ_icon"android:layout_centerHorizontal="true"android:layout_width="wrap_content"android:layout_height="wrap_content" /></com.zhy.autolayout.AutoRelativeLayout><com.zhy.autolayout.AutoRelativeLayoutandroid:layout_width="0dp"android:id="@+id/share_QQ"android:layout_weight="1"android:layout_height="match_parent"><ImageViewandroid:id="@+id/share_QQ_icon"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:layout_centerVertical="true"app:srcCompat="@drawable/qq" /><TextViewandroid:text="QQ"android:layout_marginTop="6dp"android:layout_below="@id/share_QQ_icon"android:layout_centerHorizontal="true"android:layout_width="wrap_content"android:layout_height="wrap_content" /></com.zhy.autolayout.AutoRelativeLayout><com.zhy.autolayout.AutoRelativeLayoutandroid:layout_width="0dp"android:layout_weight="1"android:id="@+id/share_QQKJ"android:layout_height="match_parent"><ImageViewandroid:id="@+id/share_QQKJ_icon"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:layout_centerVertical="true"app:srcCompat="@drawable/zone" /><TextViewandroid:text="空间"android:layout_marginTop="6dp"android:layout_below="@id/share_QQKJ_icon"android:layout_centerHorizontal="true"android:layout_width="wrap_content"android:layout_height="wrap_content" /></com.zhy.autolayout.AutoRelativeLayout><com.zhy.autolayout.AutoRelativeLayoutandroid:id="@+id/share_WB"android:layout_width="0dp"android:layout_height="match_parent"android:layout_marginRight="13dp"android:layout_weight="1"><ImageViewandroid:id="@+id/share_WB_icon"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:layout_centerVertical="true"app:srcCompat="@drawable/weibo" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@id/share_WB_icon"android:layout_centerHorizontal="true"android:layout_marginTop="6dp"android:text="微博" /></com.zhy.autolayout.AutoRelativeLayout></com.zhy.autolayout.AutoLinearLayout><TextViewandroid:background="@color/divider_color"android:layout_width="match_parent"android:layout_height="1dp" /><com.zhy.autolayout.AutoLinearLayoutandroid:id="@+id/share_cancel"android:gravity="center"android:layout_width="match_parent"android:layout_height="50dp"><TextViewandroid:gravity="center"android:textSize="15sp"android:textColor="#2d2d2d"android:text="取消"android:layout_width="wrap_content"android:layout_height="match_parent" /></com.zhy.autolayout.AutoLinearLayout>
</com.zhy.autolayout.AutoLinearLayout>

ok  没了

简单的popupwindow提示框相关推荐

  1. iOS开发:简单的Toast提示框实现

    今天小年,再分享一篇2018年度最后一篇博客,博主是以iOS开发出身,那就最后一篇博文就分享一下关于iOS的内容吧.iOS开发过程中,有些时候操作App的时候,需要给用户对应的响应提示操作,使用系统自 ...

  2. android 弹窗圆角,Android开发笔记: Android最简单的圆角提示框

    1 创建drawable文件 all_radius.xml 圆角值为20dp,背景颜色为box,边框颜色为border,可以自己定义一个颜色 android:topLeftRadius="2 ...

  3. Qt自定义一个简单的ToolTip提示框

    实现过程 因为 QToolTip 自定义样式不大方便,而且半透明也没法设置,所以需要自定义.而且,Qt 中的顶层 widget 好像默认是不支持透明样式的,可以设置: setWindowFlags(Q ...

  4. php 怎么输出alert,php简单提示框alert封装函数

    php简单提示框alert封装函数 发布于 2014-11-03 16:35:27 | 89 次阅读 | 评论: 0 | 来源: 网友投递 PHP开源脚本语言PHP(外文名: Hypertext Pr ...

  5. layer - 简单好用的Web弹出层组件使用详解1(安装配置、消息提示框)

    一.基本介绍 1,什么是 layer? layer 是一款近年来备受青睐的 web 弹层组件,可轻松实现 Alert / Confirm / Prompt / 普通提示 / 页面区块 / iframe ...

  6. Android文本长按qq风格,Android仿QQ、微信聊天界面长按提示框效果

    先来看看效果图 如何使用 示例代码 PromptViewHelper pvHelper = new PromptViewHelper(mActivity); pvHelper.setPromptVie ...

  7. qml 自定义消息框_Qt qml 自定义消息提示框

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/a844651990/article/d ...

  8. 如何使用CSS创建巧妙的动画提示框

    原文:https://webdesign.tutsplus.co... 原作:Jase Smith 翻译:Stypstive 当你的用户需要漂亮的图标给出额外的文字信息时,亦或是当他们在点击了按钮之后 ...

  9. 气泡提示效果css.html,用纯CSS3绘制高端简约的气泡提示框

    用纯css绘制一个简单的气泡提示框,对于长期关注课课家CSS3绘图教程的朋友来说是件轻而易举的事,但是程序员最不喜欢做的事情是重复造轮子,加上之前小编分享的几个气泡要么过于复杂,通用性不强,要么需要鼠 ...

最新文章

  1. 【blender教程】从头到尾全流程创建一辆吉普车
  2. Android--向SD卡读写数据
  3. Spring-AOP @AspectJ切点函数之args()和@args()
  4. 【opencv】5.cv::findContours和cv::drawContours()
  5. mysql 分表后排序_MySQL优化分库分表,为什么要分表,分表以后如何进行排序查询,业务如何设计?...
  6. mysql 表自动复制_mysql-10临时表、复制表
  7. 100个javaweb实战项目(视频+源码+文档),带你上天!
  8. html-前端调用MD5对密码进行加密
  9. 3U VPX高性能数据处理板(XC7K325T FMC载板)
  10. 外汇兑换人民币业务的居民
  11. 什么是ADB,什么是MC
  12. 适合小白的Linux入门学习教程,从安装到实操(涵盖各种常用指令,超详细!)
  13. 关于智能路由器的知识了解
  14. VUE打印 每页顶部添加一个二维码
  15. 智商和情商哪个更重要
  16. springboot项目启动问题EmbeddedWebApplicationContext
  17. 4线电子围栏安装示意图_电子围栏系统安装教程(图文)
  18. 【转】数学专业参考书整理推荐V3.0版
  19. CSDN【精品专栏】第三期
  20. 微信OAuth授权获取用户OpenId-JAVA(个人经验)

热门文章

  1. 微信小程序获取附近商家
  2. golang中struct
  3. vue.js 表格表单序号
  4. C++程序设计:补齐函数求长方体体积
  5. 【超详细】SpringBoot与Shiro整合-权限管理实战实操(附源码地址)
  6. Gitbook 插件安装 - 导航目录折叠 chapter-fold
  7. 2021-06-26一文看尽深度学习中的20种卷积(附源码整理和论文解读)
  8. 白醋泡大蒜,治疗灰指甲。以下为详细操作,供需要的人参考
  9. 单片机常用环形队列--ringbuff
  10. 网站加入QQ在线即时交谈的代码