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

来源:互联网 发布:网络免费打电话啥软件 编辑:程序博客网 时间:2024/05/20 11:51
/** * 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);    }}

阅读全文
0 0
原创粉丝点击