PopWindows背景半透明设置

本文介绍了如何在Android中创建一个PopupWindow,包括使用showAtLocation()和showAsDropDown()显示位置,设置PopupWindow外部点击消失,背景半透明以及添加动画效果的方法。同时,针对华为手机屏幕背景不变的问题提供了解决方案。
摘要由CSDN通过智能技术生成

PopupWindow可以实现跟Dialog一样的效果,但相对于Dialog,PopupWindow可以设置任意的显示位置,其中有
1、showAtLocation()显示在指定位置,有两个方法重载:
public void showAtLocation(View parent,int gravity,int x,int y)
public void showAtLocation(View parent,int gravity,int x,int y)
这里我们可以根据具体的位置计算弹出窗口的位置

2、showAsDropDown()显示在一个参照物View的周围,有三个方法重载:
public void showAsDropDown(View anchor) 默认显示在参照物View的下方
public void showAsDropDown(View anchor, int xoff, int yoff)可以设置相应的偏移量显示
public void showAsDropDown(View anchor, int xoff, int yoff, int gravity)相对位置中设置gravity

PopupWindow设置外部点击消失必须设置
.setOutsideTouchable(true);
.setBackgroundDrawable(Drawable background);
二者缺一不可,否则没有效果。
代码如下:

View view = LayoutInflater.from(getActivity()).inflate(R.layout.warn_coach_dialog, null);
final PopupWindow popupWindow = new PopupWindow(view, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值