Android Nougat PopupWindow showAsDropDown(...) Gravity not working

android popupwindow
android - popupwindow above a specific view
android popup window show at location
android popup window animation
popupwindow showatlocation
custom popup window android
popup window anchor android
android popup window rtl

I have this code.

PopupWindow popUp = new PopupWindow();
popUp.setFocusable(true);
popUp.setOutsideTouchable(true);        
popUp.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
popUp.setHeight(600);

popUp.setContentView(anchorView);
popUp.showAsDropDown(anchorView);
popUp.update();

And its perfectly works on Android Version < Android Nougat. But in Android Nougat, the popup is being displayed at the top of the screen instead of relative to the anchor view.

It seems a bug in android 7.0. But you can solve it with a compatible way.

PopupWindow popUp = new PopupWindow();
popUp.setFocusable(true);
popUp.setOutsideTouchable(true);        
popUp.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
popUp.setHeight(600);

popUp.setContentView(anchorView);
  if (android.os.Build.VERSION.SDK_INT >=24) {
     int[] a = new int[2]; //getLocationInWindow required array of size 2
     anchorView.getLocationInWindow(a);
     popUp.showAtLocation(((Activity) mContext).getWindow().getDecorView(), Gravity.NO_GRAVITY, 0 , a[1]+anchorView.getHeight());
    } else{
     popUp.showAsDropDown(anchorView);
}

popUp.update();

Google will fix this bug in the future build. And there is a final workaround. You need give the height when creating pop.

PopupWindow popup = new PopupWindow(contentView, with, height);

Init pop as above, and you can only use popUp.showAsDropDown(anchorView) show this popup. In this way, you can ignore the version of the Android API.

Bug when call popupWindow.showAsDropDown() on API 24. � Issue , showAsDropDown() funcion, the is a bug on Api 24, you should /android- nougat-popupwindow-showasdropdown-gravity-not-working. Hello, On your AutocompletePopup class, on line 376, when you call popupWindow.showAsDropDown() funcion, the is a bug on Api 24, you should replace the current line to : `` // API 24 PopupWindow bu

7.0 and 7.1 to achieve different, so to be dealt with separately.

The following method I tested in the virtual machine(7.0 and 7.1), no problem.

public void showFilterWindow(Context context, PopupWindow popupWindow,View showView, int xoff, int yoff) {
        if (Build.VERSION.SDK_INT < 24) {
            //7.0 The following system is used normally
            popupWindow.showAsDropDown(showView, xoff, yoff);
        } else {
            int[] location = new int[2];
            showView.getLocationOnScreen(location);
            int offsetY = location[1] + showView.getHeight() + yoff;
            if (Build.VERSION.SDK_INT == 25) {
                //【note!】Gets the screen height without the virtual key
                WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
                int screenHeight = wm.getDefaultDisplay().getHeight();
                /*
                 * PopupWindow height for match_parent,
                 * will occupy the entire screen, it needs to do special treatment in Android 7.1
                */
                popupWindow.setHeight(screenHeight - offsetY);
            }
            //Use showAtLocation to display pop-up windows
            popupWindow.showAtLocation(showView, Gravity.NO_GRAVITY, 0, offsetY);
        }
    }

Android Nougat PopupWindow showAsDropDown () Gravity no , Adem�s, lo m�s probable es un problema relacionado, inform� sobre PopupWindow.showAtLocation() : https://code.google.com/p/android/issues/ detail?id=� On Android 24, apparently, PopupWindow changed behavior when it did not fit the screen. In previous versions the PopupWindow position was adjusted automatically, without changing the size. See on Android 23 (position adjusted): But, on Android 24 the size is adjusted automatically: I will work to find a solution, but suggestions are welcome 😄

Looks like this problem appears only in Android 7.0 (API 24). In 7.1.1 (API 25) everything is OK on same devices. After some research defined that the problem caused by popUp.update(), like it is already mentioned by Marilia. But if you just remove popUp.update(), the popup won't appear in versions prior to API 24. In order to avoid this the only way now is to use version check and don't use update() method only on devices with API 24. Here is the solution, which worked for me:

if (Build.VERSION.SDK_INT != 24) {
   popup.update(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
}

Tested it on different devices and APIs and it works well everywhere from API 18 and up to API 25.

android, Android Nougat 7.1.1 showAtLocation(…) Gravity not working. This is related to this question: Android Nougat PopupWindow showAsDropDown() Gravity not� -Center clock mode does not working and when I turn it on, send me to the lock screen.-Volume step increaser seems just added more steps cause it automatically start again same as 0 to 15th and 16th to 30.-Lock screen tweaks also not working for me.-Battery stats works fine-Status bar brightness control works fine Great works! Thank you👍🏻️

Do you really need that popUp.update(); in your code? I was having a similar problem, in my case I didn't need the popUp.update(); and removing it made the popup gravity behave as expected.

Also, this is most likely a related issue, reported about PopupWindow.showAtLocation():

https://code.google.com/p/android/issues/detail?id=221001

android.widget.PopupWindow#showAsDropDown, This page shows Java code examples of android.widget.PopupWindow# showAsDropDown. setGravity(Gravity.BOTTOM); popupWindow; }. Example 7� You have set the PopupWindow set as a drop down. So for partially visible views, PopupWindow won’t show since it goes off the screen area. The fix for this issue is to show the PopupWindow above the view. Luckily the showAsDropDown() has another overloaded method with extra arguments like below, showAsDropDown(View anchor, int xoff, int yoff)

This code worked for me. Please try it

    protected void showSortPopup(View anchorView) {


    if (Build.VERSION.SDK_INT >= 25) {
        Rect rectf = new Rect();
        anchorView.getGlobalVisibleRect(rectf);
        int offsetY = (rectf.top + anchorView.getHeight());
        WindowManager wm = (WindowManager) Manager.getInstance().getCurrentActivity().getSystemService(Context.WINDOW_SERVICE);
        int screenHeight = wm.getDefaultDisplay().getHeight();
        mPopup.setHeight(screenHeight - offsetY);
    }
    mPopup.showAsDropDown(anchorView);

}

Problems after Android PopupWindow 7.0, Problems after Android PopupWindow 7.0, Programmer Sought, the best programmer technical posts sharing site. Popuwindow setting showAsDropDown(view) is not under a view Obviously this bug is related to our setting of Gravity. If no parent scroll view can be scrolled, the bottom-left * corner of the popup is pinned at the top left corner of the anchor view.</p> * * @param anchor the view on which to pin the popup window * * @see #dismiss() */ public void showAsDropDown(View anchor) { showAsDropDown(anchor, 0, 0); } /** * <p>Display the content view in a popup window

android.widget.PopupWindow.showAsDropDown java code , showAsDropDown (Showing top 20 results out of 702). Common KITKAT) @ Override public void showAsDropDown(View anchor, int xoff, int yoff, int gravity) { if (Build.VERSION. Spinner does not wrap text -- is this an Android bug? _p. A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate(i

Android Nougat 7.1.1 showAtLocation(…) Gravity not, This is related to this question: Android Nougat PopupWindow showAsDropDown() Gravity not working. However, when I applied this fix:

Android Nougat PopupWindow showAsDropDown () Gravity not , Android Nougat PopupWindow showAsDropDown () Gravity not working. Ho questo codice. PopupWindow popUp = new PopupWindow(); popUp.

Comments
  • It works only in api 24 not in 25. Pls provide if anybody knows answer to this issue.
  • I asked a question specifically for API 25: stackoverflow.com/questions/41973893/…
  • The bug still exists on Oreo, at least on the emulators. I would recommend changing the Build.VERSION.SDK_INT check to be >=25
  • Please post complete code. I'm having problems with API 25 when I created a similar fix: stackoverflow.com/questions/41973893/…