美文网首页
使用PickerView 弹出窗口与手机虚拟导航按键重叠问题

使用PickerView 弹出窗口与手机虚拟导航按键重叠问题

作者: 微风LE | 来源:发表于2019-12-20 18:28 被阅读0次

    Android-PickerView

    很实用的仿IOS选择器库
    在使用过程中与国产部分手机虚拟导航按键有重叠问题
    以时间选择器为例:

    var timePicker= TimePickerBuilder(this, OnTimeSelectL ...(该处省略)
    //适配方法 kotlin
    var layoutParams:FrameLayout.LayoutParams= timePicker.dialogContainerLayout.layoutParams as FrameLayout.LayoutParams
    layoutParams.bottomMargin=UIHelper.getNavigationBarHeight(activity)
    timePicker.dialogContainerLayout.layoutParams=layoutParams
    
    timePicker.show()
    

    UIHelper.getNavigationBarHeight(activity) 是写的一个获得手机虚拟导航按键高度的方法
    getNavigationBarHeight(...)如下:

    /**
     * 获得NavigationBar的高度
     */
    public static int getNavigationBarHeight(Activity activity) {
        int result = 0;
        Resources resources = activity.getResources();
        int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
        if (resourceId > 0 && checkHasNavigationBar(activity)) {
            result = resources.getDimensionPixelSize(resourceId);
        }
        return result;
    }
    
    /**
     * 判断是否有NavigationBar
     * @param activity
     * @return
     */
    public static boolean checkHasNavigationBar(Activity activity) {
        WindowManager windowManager = activity.getWindowManager();
        Display d = windowManager.getDefaultDisplay();
        DisplayMetrics realDisplayMetrics = new DisplayMetrics();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            d.getRealMetrics(realDisplayMetrics);
        }
        int realHeight = realDisplayMetrics.heightPixels;
        int realWidth = realDisplayMetrics.widthPixels;
        DisplayMetrics displayMetrics = new DisplayMetrics();
        d.getMetrics(displayMetrics);
        int displayHeight = displayMetrics.heightPixels;
        int displayWidth = displayMetrics.widthPixels;
        return (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0;
    }
    

    当然还有别的适配方法,这种方法来的比较直接,不喜勿喷哈

    相关文章

      网友评论

          本文标题:使用PickerView 弹出窗口与手机虚拟导航按键重叠问题

          本文链接:https://www.haomeiwen.com/subject/rpbinctx.html