首页 > 系统 > Android > 正文

Android的软键盘和主题冲突的解决方法

2019-11-07 23:56:40
字体:
来源:转载
供稿:网友

把布局的layout换成这个layout试一下

问题描述..我们要做一个状态栏设置颜色(也就是和我们的主题色一致的效果).我把主题换成 noactionbar的主题了,然后就出现很多弹出软键盘的时候布局没有移动的bug..找了很久找到这个方法希望对你有帮助.

需要注意的是这个方式解决只能兼容到21及以上版本

public class FitsSystemWindowsExceptTopFrameLayout extends FrameLayout {

    public FitsSystemWindowsExceptTopFrameLayout(Context context) {        super(context);    }    public FitsSystemWindowsExceptTopFrameLayout(Context context, AttributeSet attrs) {        super(context, attrs);    }    public FitsSystemWindowsExceptTopFrameLayout(Context context, AttributeSet attrs,                                                 int defStyleAttr) {        super(context, attrs, defStyleAttr);    }    @RequiresApi(Build.VERSION_CODES.LOLLipOP)    public FitsSystemWindowsExceptTopFrameLayout(Context context, AttributeSet attrs,                                                 int defStyleAttr, int defStyleRes) {        super(context, attrs, defStyleAttr, defStyleRes);    }    @Override    public WindowInsets onApplyWindowInsets(WindowInsets insets) {        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {            setPadding(insets.getSystemWindowInsetLeft(), 0, insets.getSystemWindowInsetRight(),                    insets.getSystemWindowInsetBottom());            return insets.replaceSystemWindowInsets(0, insets.getSystemWindowInsetTop(), 0, 0);        } else {            return super.onApplyWindowInsets(insets);        }    }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表