Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PopupWindow overlaps soft buttons on Android 5.0

Tags:

android

I have a simple PopupWindow that I create with the following code (the code is in C#, the Java code should be basically the same)

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, 0);

On pre-Lollipop devices, this popup looks fine, but on Android 5.0, the popup overlaps the soft buttons:

PopupWindow Lollipop

Here's the PopupWindow on an Android 4.4 device:

enter image description here

Does anyone have an idea why this happens and how this can be fixed?

like image 842
Flagbug Avatar asked Jun 14 '15 08:06

Flagbug


1 Answers

This is possible bug in android api 21 that's why they introduced popup.setAttachedInDecor(true/false); method in api 22 however there is a workout, you can set right y coordinate for your popup as follows:

Rect rect = new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
int winHeight = getWindow().getDecorView().getHeight();
popup.showAtLocation(rootView, Gravity.BOTTOM, 0, winHeight-rect.bottom);
like image 130
Vilen Avatar answered Nov 06 '22 13:11

Vilen