华为Mate9导航栏遮挡PopupWindow底部布局

一、上图

         华为Mate9导航栏遮挡PopupWindow底部布局_第1张图片


二、问题描述

        华为Mate9手机,UI的表现形式是底部黑色的导航栏遮挡住了PopupWindow底部重置与确认按钮的布局。


三、问题分析与解决思路

        网上很多解决方法都是说设置popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);或者popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);来处理,在Android6.0操作系统以下没有问题,但是在Android7.0中,不能解决这个问题。

        尝试过很多方法失败后,我将思路转到计算PopupWindow高度,通过showAtLocation()方法去显示,然后问题解决。具体代码如下:

    public void initPopupWindow(Activity searchResultActivity, View bindView,
            List allFiltrarteList, List hotCityList) {
        this.context = searchResultActivity;
        this.bindView = bindView;
        this.allFiltrarteList = SearchResultBiz
                .getInstance()
                .getAllFiltrarteList(SearchResultBiz
                        .getInstance()
                        .getSelectValueList(), allFiltrarteList);
        this.priceMap = SearchResultBiz
                .getInstance()
                .getPriceMap();
        this.goodsType = SearchResultBiz
                .getInstance()
                .getGoodsType();
        this.hotCityName = SearchResultBiz
                .getInstance()
                .getHotCityName();
        this.hotCityList = SearchResultBiz
                .getInstance()
                .getHotCityList(hotCityName, hotCityList);
        this.searchResultActivity = (SearchResultActivity) searchResultActivity;

        View dialogView = LayoutInflater
                .from(context)
                .inflate(R.layout.newgoodsfiltrate, null);
        createPopupWindow(dialogView);

        int statusBarHeight = getStatusBarHeight(context);
        int screenHeight = ScreenUtil.getScreenHeight(context);
        int popupWindowHeight = screenHeight - statusBarHeight - (int) DisplayUtil
                .dip2px(context, 84);

        popupWindow = new PopupWindow(dialogView, LayoutParams.MATCH_PARENT,
                popupWindowHeight);
        // 此处必须设置,否则点击事件无效,选择不了
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        // 设置显示动画
        popupWindow.setAnimationStyle(R.style.PopupWindowAinmation02);
        // 设置边缘点击可消失
        popupWindow.setOutsideTouchable(true);

        //解决在EditText中输入把popupwindow布局往上顶的问题
        popupWindow.setSoftInputMode(WindowManager.LayoutParams
                .SOFT_INPUT_ADJUST_PAN);

        // 为了设置返回按钮关闭弹层
        popupWindow.setFocusable(true);

        dialogView.setOnKeyListener(new PopOnKeyListener());
        popupWindow.setTouchInterceptor(new PopTouchListener());

    }

    /**
     * 获取状态栏高度
     *
     * @param context
     * @return
     */
    public int getStatusBarHeight(Context context) {
        int result = 0;
        int resourceId = context
                .getResources()
                .getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = context
                    .getResources()
                    .getDimensionPixelSize(resourceId);
        }
        return result;
    }

    /**
     * 显示PopupWindow界面
     */
    public void show() {

        if (this.isShowing()) {
            return;
        }

        isClickConfirm = false;

        if (null != searchResultActivity && !searchResultActivity.isFinishing()) {
            if (null == bindView) {
                bindView = searchResultActivity
                        .getWindow()
                        .getDecorView();
            }

            popupWindow.showAtLocation(bindView, Gravity.BOTTOM, 0, 0);
        }

    }


        













你可能感兴趣的:(02_Android)