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

Posted 清风百草

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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);
        

    

 

 

 

 

 

        

 

 

 

 

 

 

 

 

 

 

 

 

以上是关于23华为Mate9导航栏遮挡PopupWindow底部布局的主要内容,如果未能解决你的问题,请参考以下文章

PopupWindow设置底部,兼容7.0 与 在华为等带虚拟控制栏被遮挡

android 显示内容被底部导航栏遮挡

android 显示内容被底部导航栏遮挡

Android:虚拟按键/导航键遮挡内容的解决方案

状态栏、导航栏、PopupWindow的使用

安卓 PopupWindow 的 2 个坑