Android 7.0手机popwindow的showAsDro
2017-04-20 本文已影响136人
满天星爱我
最近用7.0的android手机测试项目,发现popwindow的showAsDropDown失效了,
不过最终找到了两种解决方案:
1、重写showAsDropDown方法:
@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;
setHeight(h);
}
super.showAsDropDown(anchor);
}
2、使用showAtLocation方法:
if (Build.VERSION.SDK_INT >= 24) {
int[] point = new int[2];
v.getLocationInWindow(point);
mPopWindow.showAtLocation(((Activity) mContext).getWindow().getDecorView(), Gravity.NO_GRAVITY, 0, point[1] + v.getHeight());
} else {
mPopWindow.showAsDropDown(v);
}