设置透明状态栏后,弹出键盘的冲突问题

设置透明导航栏

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}

rootView中设置:  

fitsSystemWindows="true"

  键盘弹出模式

android:windowSoftInputMode="adjustResize" 挤压模式

但是此时遇到冲突了,键盘直接遮挡editText了。

 

参考:http://www.jianshu.com/p/1b22a1d2a7b8

核心代码:重写rootView中的两个方法

    @Override
    protected boolean fitSystemWindows(Rect insets) {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            insets.left = 0;
            insets.top = 0;
            insets.right = 0;
        }
        return super.fitSystemWindows(insets);
    }

    @Override
    public WindowInsets onApplyWindowInsets(WindowInsets insets) {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            return super.onApplyWindowInsets(insets.replaceSystemWindowInsets(0, 0, 0, insets.getSystemWindowInsetBottom()));
        } else {
            return insets;
        }
    }

  

posted on 2017-03-24 13:44  wjw334  阅读(198)  评论(0编辑  收藏  举报

导航