popupwindow在android7.0出現全屏解決方案
阿新 • • 發佈:2018-11-05
在android7.0的版本測出popupwindow使用showAsDropDown方法之後,並不能顯示在指定view的下方,而是全屏顯示,只要重寫showAsDropDown判斷一下版本就好了.建議不要使用popupwindow了,使用DialogFragment代替
public class SingleFlowPopuwindow extends PopupWindow {
public SingleFlowPopuwindow (View contentView, int width, int height){
super(contentView,width,height);
}
@Override
public void showAsDropDown(View anchor) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Rect visibleFrame = new Rect();
anchor.getGlobalVisibleRect(visibleFrame);
int height = anchor.getResources().getDisplayMetrics().heightPixels - visibleFrame.bottom;
setHeight(height);
}
super .showAsDropDown(anchor);
}
@Override
public void showAsDropDown(View anchor, int xoff, int yoff) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Rect visibleFrame = new Rect();
anchor.getGlobalVisibleRect(visibleFrame);
int height = anchor.getResources().getDisplayMetrics().heightPixels - visibleFrame.bottom;
setHeight(height);
}
super .showAsDropDown(anchor, xoff, yoff);
}
}