PopupWindow重叠Android 5.0上的软按钮

前端之家收集整理的这篇文章主要介绍了PopupWindow重叠Android 5.0上的软按钮前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个简单的PopupWindow,我使用以下代码创建(代码在C#中,Java代码应该基本相同)
View popupView = LayoutInflater.From(this.Activity).Inflate(Resource.Layout.LectionFooter,null);

var popup = new PopupWindow(popupView,ViewGroup.LayoutParams.MatchParent,ViewGroup.LayoutParams.WrapContent,false)
{
    OutsideTouchable = true,AnimationStyle = Resource.Style.FooterAnimation
};

popup.SetBackgroundDrawable(new BitmapDrawable());
popup.ShowAtLocation(rootView,GravityFlags.Bottom,0);

在pre-Lollipop设备上,这个弹出窗口看起来不错,但在Android 5.0上,弹出窗口与软按钮重叠:

这是Android 4.4设备上的PopupWindow:

有谁知道为什么会发生这种情况以及如何解决这个问题?

解决方法

这可能是android api 21中的错误,这就是他们在api 22中引入 popup.setAttachedInDecor(true/false);方法的原因
但是如果有锻炼,您可以为弹出窗口设置正确的y坐标,如下所示:
Rect rect = new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
int winHeight = getWindow().getDecorView().getHeight();
popup.showAtLocation(rootView,Gravity.BOTTOM,winHeight-rect.bottom);
原文链接:https://www.f2er.com/android/316377.html

猜你在找的Android相关文章