0

My activity has a popup window defined like this :

this.navigationMenuPopupWindow = new PopupWindow(View.inflate(this, R.layout.popup_navigation, null), ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
this.navigationMenuPopupWindow.setWidth((int) this.getResources().getDimension(R.dimen.navigation_popup_width));
this.navigationMenuPopupWindow.setBackgroundDrawable(this.getDrawable(R.drawable.main_bg_navigation_menu));
this.navigationMenuPopupWindow.setElevation(43);
this.navigationMenuPopupWindow.setFocusable(true);
this.navigationMenuPopupWindow.setOutsideTouchable(true);

I would like to position the popup under the anchor. So I naturally tried to add this line :

this.navigationMenuPopupWindow.setOverlapAnchor(false);

Unfortunately, it requires the API 23. How can I achieve the same result but that it is compatible with the API 21?

I think I can resolve this by modifying my app style, but I don't know exactly how. By the way, this can affect all the PopupWindows of the app, it's not a problem I only have that one. Thank you for your help!

Greelings
  • 4,964
  • 7
  • 34
  • 70
  • I think this should help http://stackoverflow.com/questions/9467026/changing-position-of-the-dialog-on-screen-android – Vivek Mishra Jan 21 '17 at 12:43

1 Answers1

0

You need to use PopupWindowCompat.

PopupWindowCompat.setOverlapAnchor(this.navigationMenuPopupWindow,true);

Be aware that the PopupWindowCompat.setOverlapAnchor has no implementation before API 21.

Amr
  • 50
  • 1
  • 10