输入法弹出,界面自动响应

当输入法出现时,为确保系统将布局大小调整为可见,可使用清单的  元素中

android:windowSoftInputMode="adjustResize"。

而为使 adjustResize元素可以成功起作用,要在activity的根布局上添加fitsSystemWindows="true"。

 

输入法弹出响应与沉浸式状态栏冲突

但如果此时页面是沉浸式状态栏状态,则会发现沉浸式失效、状态栏颜色异常。原本延伸至状态栏的显示内容,被顶了下来。

本质上是fitSystemWindows与沉浸式显示的冲突,给显示内容与状态栏之间插入了系统组件的padding距离,手动置为0即可。

网上的推荐解决办法是,重写activity根布局的viewGroup组件的fitSystemWindows()方法。

    @Override    protected boolean fitSystemWindows(Rect insets) {        insets.top = 0;        return super.fitSystemWindows(insets);    }

 

fitSystemWindows()方法,在高版本中被废弃

但是今天发现,在高版本中该fitSystemWindows()方法已被废弃,于是在源码方法注释中看到,推荐使用

dispatchApplyWindowInsets(WindowInsets)、
onApplyWindowInsets(WindowInsets)、
setOnApplyWindowInsetsListener(android.view.View.OnApplyWindowInsetsListener)等方法来替代。

 

在高版本新方法,dispatchApplyWindowInsets方法中,逻辑的相同实现

于是在新方法中重写 相同逻辑的实现、亲测可用:

    @Override    public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) {        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {            Insets b = null;            b = Insets.of(0, -insets.getSystemWindowInsets().top                    , 0, 0);            //使两个inset.top字段相消为0            Insets result = Insets.add(insets.getSystemWindowInsets(), b);            WindowInsets.Builder builder=new WindowInsets.Builder(insets).setSystemWindowInsets(result);            return super.dispatchApplyWindowInsets(builder.build());        }        return super.dispatchApplyWindowInsets(insets);    }

***********************************************************************************************************************************

参考资料:

https://developer.android.google.cn/training/keyboard-input/visibility

https://www.jianshu.com/p/94072850ba58

https://blog.csdn.net/u012006926/article/details/53521198

 

 

更多相关文章

  1. 浅谈Java中Collections.sort对List排序的两种方法
  2. Python list sort方法的具体使用
  3. python list.sort()根据多个关键字排序的方法实现
  4. Android面试系列文章2018之Android部分ContentProvider篇
  5. Android事件处理方法总结-Handler消息处理
  6. Android原生json类org.json.JSONObject初步使用
  7. 《Android移动应用基础教程》(Android(安卓)Studio)(第二版)黑马教程
  8. Android中数据存储——SharedPreferences存储数据
  9. 2011Android技术面试整理附有详细答案(包括百度、新浪、中科软等

随机推荐

  1. QQ登陆及分享
  2. 手把手教你给Eclipse配制Android
  3. Android真机网络adb联机调试初探
  4. android TextView 文本过长时用滚动条显
  5. Android(安卓)viewPage notifyDataSetCha
  6. android:网路检测
  7. android 傻瓜式 MultiDex 插件,从此再也不
  8. 一个android参考网站,工具+源码
  9. minSdkVersion各个版本号对应android版本
  10. android源码下载-等待提示动画