Android PopupWindow 7.0適配遇到的一些坑
阿新 • • 發佈:2019-01-07
PopupWindow在使用showAsDropDown的時候,在7.0以後不能正常顯示;
解決方法網上貼出來很多,最多的就是重寫showAsDropDown,計算一下高度
@Override public void showAsDropDown(View anchor) { if(Build.VERSION.SDK_INT >= 24) { //7。0適配問題 Rect rect = new Rect(); anchor.getGlobalVisibleRect(rect); int h = anchor.getResources().getDisplayMetrics().heightPixels- rect.bottom; setHeight(h); } super.showAsDropDown(anchor); }
這是最常見的一個坑,還有一個就是適配全面屏手機的時候,還是會出現這個問題(紅米 5 plus)
還需要做一下全面屏適配
1.在AndroidManifest的Application下加一個標籤
<meta-data android:name="android.max_aspect" android:value="2.1" />
或者
<application ... android:resizeableActivity= "true">
第一次,可能有不足的地方,望大神勿噴,多多指教