问题描述:PopupWindow在7.0级以上手机上showAsDropDown()方法失效,任然全屏。
解决方案:自定义CustomPopupWindow继承PopupWindow,重写showAsDropDown()方法
@Override
public void showAsDropDown(View anchor) {
//Android7.0适配
if (Build.VERSION.SDK_INT >= 24) {
Rect rect = new Rect();
anchor.getGlobalVisibleRect(rect);
int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom;
setHeight(h);
}
super.showAsDropDown(anchor);
}
//重点是此方法
@Override
public void showAsDropDown(View anchor, int xoff, int yoff) {
//Android7.0适配
if (Build.VERSION.SDK_INT >= 24) {
Rect rect = new Rect();
anchor.getGlobalVisibleRect(rect);
int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom;
setHeight(h);
}
super.showAsDropDown(anchor, xoff, yoff);
}