我的一個頁面中用到了popupwindow,之前都沒問題的,測試跑來說android7.0不對了,把原來的button擋住了(點擊button彈出popupwindow)
重寫showAsDropDown(view)就解決了。
public class SupportPopupWindow extends PopupWindow { public SupportPopupWindow(View contentView, int width, int height){ super(contentView,width,height); } @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); } @Override public void showAsDropDown(View anchor, int xoff, int yoff) { 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); } }
