话不多说,上代码
一、状态栏
popupWindow.setClippingEnabled(false);
不建议使用,虽然能够是状态栏适配,但是会在华为等具有虚拟按键的手机上无法适配虚拟按键
2.建议使用,目前使用良好
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
try {
Field mLayoutInScreen = PopupWindow.class.getDeclaredField("mLayoutInScreen");
mLayoutInScreen.setAccessible(true);
mLayoutInScreen.set(popupWindow, true);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
二、底部虚拟按键
//适配底部虚拟按键
popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
没有废话,做个记录