popWindow 在Android7.0上的显示位置不管怎么设置都在屏幕的顶部,这是7.0的bug,已在7.1修复,但是7.0还是需要我们自己解决的,以及在小米mix2全面屏导航键留白,显示不全。
如图:
方法如下:
@Override
public void showAsDropDown(View anchor) {
if(Build.VERSION.SDK_INT >= 24) {
Rect rect = new Rect();
anchor.getGlobalVisibleRect(rect);
int h = anchor.getResources().getDisplayMetrics().heightPixels - rect.bottom+anchor.getResources().getDimensionPixelSize(anchor.getResources().getIdentifier("navigation_bar_height", "dimen", "android"));
setHeight(h);
}
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N) {
int[] a = new int[2];
anchor.getLocationInWindow(a);
showAtLocation(anchor, Gravity.NO_GRAVITY, 0, a[1] + anchor.getHeight() + 0);
}
super.showAsDropDown(anchor);
}完美解决这俩大问题 !!睡觉睡觉。。。