0

I using the code below to show a PopupWindow but it not work well.

View view = getWindow().getDecorView().getRootView();    
popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, 0, 0);

result in Custom Phone API 25 (it work well) enter image description here

 popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, 0, 30);

result in Custom Phone API 25 (PopupWindow is as same as set y=0 even we set it = 30) enter image description here

 popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, 0, 60);

result in Custom Phone API 25 (PopupWindow have margin top) enter image description here

 popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, 0, 60);

result in Google Nexus 5 API 21 (PopupWindow above status bar) enter image description here

I want to show a PopupWindow below status bar 20dp in all devices. Any help or suggestion would be great appreciated.

Linh
  • 57,942
  • 23
  • 262
  • 279
  • You can display your popupwindow under one predefined view (Set that view visibility to invisible) . for the reference refer this https://stackoverflow.com/a/7502433/1848157 – Radhey Oct 23 '17 at 04:47
  • rather than set hard code value of #y , you can calculate exact location of that predefined view. – Radhey Oct 23 '17 at 04:49
  • @Radhey thank you so much. Using `predefined view` is a correct way, but Unfortunately, I am using this `PopupWindow` is many screen (activity) so I need to define many `predefined view`. Any suggestion? – Linh Oct 23 '17 at 04:51
  • you can calculate statusbar height programmatically and set #y accordingly. – Radhey Oct 23 '17 at 04:58
  • Are you using toolbar? – AbhayBohra Oct 23 '17 at 05:22

0 Answers0