Android 7.0 PopupWindow 的showAsDropDown(View v)适配

来源:互联网 发布:用工作站玩游戏知乎 编辑:程序博客网 时间:2024/05/20 13:08

问题描述: popupWindow使用popupwidow 使用showAsDropDown 显示在自定控件之下,在7.0之前的系统能显示正常,在7.0的系统不能正确的显示指定控件的下方
解决方案: 重写public void showAsDropDown(View anchor);

@Override

public void showAsDropDown(View anchor) {    if (Build.VERSION.SDK_INT >= 24) {// 只有7.0 的系统有这个问题        mEditText.setFocusable(false);        HideKeyboard(mEditText);        int[] location = new int[2];        anchor.getLocationOnScreen(location);        int x = location[0];        int y = location[1];        showAtLocation(anchor, Gravity.NO_GRAVITY, 0, y + anchor.getHeight());    } else {        super.showAsDropDown(anchor);    }}

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