I’m facing an issue with PopupWindow
where even after setting its position to (0, 0)
, it doesn’t display at the top of the screen. The status bar is hidden in my activity. How can I ensure PopupWindow
displays at the very top of the screen?
I have tried using different parentViews, and these parentViews are correctly displayed at the top-left corner of the screen. However, when I call popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, 0, 0)
, the PopupWindow
always appears with a gap from the top, exactly the height of the status bar.
Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(() -> {
View contentView= LayoutInflater.from(this).inflate(R.layout.popup_window_content,null,false);
PopupWindow popupWindow=new PopupWindow(this);
popupWindow.setContentView(contentView);
popupWindow.setHeight(ViewUtil.dp2px(getResources().getDimension(R.dimen.dp_79)));
popupWindow.setWidth(ViewUtil.dp2px(getResources().getDimension(R.dimen.screen_width)));
View view =mBinding.bg;
Log.d("debug", "pos: "+view.getX()+" "+view.getY());
popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, 0, 0);
}, 1000);
screenshot illustrating the issue
ei zao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I solved it,it‘s a fool question,just use statusWindow.setClippingEnabled(false);
ei zao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.