7

Here is my code for show a PopupWindow

View rootView = activity.getWindow().getDecorView().getRootView();
mPopupWindow.showAtLocation(rootView, Gravity.NO_GRAVITY, 0, 0);

When I test it on Samsung, Nexus device it show below the status bar
However when I test it on Sony device it show above the status bar (like the image below)

So which device display correct or what I do wrong ? Any help or suggestion would be great appreciated

enter image description here

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Linh
  • 57,942
  • 23
  • 262
  • 279

1 Answers1

2

I solve my problem by create a temp View at top-left (topLeftView in below code).
Then when I show the PopupWindow, I will show it at (0, the y coordinate of topLeftView) not (0,0)

View topLeftView = findViewById(R.id.top_left_View);
int topLeftPos[] = new int[2];
topLeftView.getLocationOnScreen(topLeftPos);

mPopupWindow.showAtLocation(topLeftView, Gravity.NO_GRAVITY, 0, topLeftPos[1]);

I think this solution will work for all devices

Linh
  • 57,942
  • 23
  • 262
  • 279
  • It looks like the Android flavor in Sony devices calculate the top left corner as the physical top left corner while the Nexus and Samsung devices calculate the top left corner excluding the status bar. – ucsunil Jan 04 '17 at 19:59