• Android输入法遮挡了输入框,使用android:fitsSystemWindows="true"后界面顶部出现白条解决方案


    我的最外层是LinearLayout,自定义CustomLinearLayout继承LinearLayout,重写fitSystemWindows和onApplyWindowInsets两个方法:

    public class CustomLinearLayout extends LinearLayout {
        public CustomLinearLayout(Context context) {
            super(context);
        }
    
        public CustomLinearLayout(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public CustomLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
        }
    
        public CustomLinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
            super(context, attrs, defStyleAttr, defStyleRes);
        }
    
        @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);
        }
    
        @RequiresApi(api = Build.VERSION_CODES.KITKAT_WATCH)
        @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;
            }
        }
    }

    替换一下布局文件即可解决问题

  • 相关阅读:
    JQuery对象与Dom对象相互转化
    JQuery练习demo2
    ExtJs简单的登录界面制作
    JQuery练习demo1(隔行变色)
    html标签label的for属性
    Android环境搭建(Windows)
    JQuery表格操作练习
    ExtJs简单动态ComboBox
    Asp.Net母版页的使用
    SQL经典语句大全
  • 原文地址:https://www.cnblogs.com/loaderman/p/11051005.html
Copyright © 2020-2023  润新知