PopupWindow is above the status bar on any device

Here is my code to display PopupWindow

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

When I test it on a Samsung device, Nexus , it shows the status bar below
However, when I test it on a Sony device, it shows the status bar above (for example, the image below)

So which device is displayed correctly or what am I doing wrong? Any help or suggestion would be greatly appreciated.

enter image description here

+7
android sony popupwindow nexus-s
source share
1 answer

I solve my problem by creating temp View in top-left ( topLeftView in lower code).
Then when I show PopupWindow , I will show it in (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

+1
source share

All Articles