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

一、上图

         

 

二、问题描述

        华为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<AllFiltrarteBean> allFiltrarteList, List<HotCityBean> 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);
        }

    }

 

 

 

 

 

        

 

 

 

 

 

 

 

 

 

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值