在Android 7.0上PopupWindow.showAsDropDown不起作用的解决方法

xiaoxiao2021-02-28  153

/** * Created by twy on 2017/7/7. */ public class MyPopWindow extends PopupWindow { public MyPopWindow(final Activity context,View view){ LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); int h = context.getWindowManager().getDefaultDisplay().getHeight(); int w = context.getWindowManager().getDefaultDisplay().getWidth(); this.setContentView(view); this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); this.setFocusable(true); this.setOutsideTouchable(true); this.update(); ColorDrawable dw = new ColorDrawable(-00000); this.setBackgroundDrawable(dw); this.setAnimationStyle(R.style.AnimationPreview); } @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); } }
转载请注明原文地址: https://www.6miu.com/read-17328.html

最新回复(0)