一般用法

  • 设置属性:
 android:windowSoftInputMode="stateVisible|adjustResize" android:fitsSystemWindows="true"

以上做法会导致toolbar向下平移了statusbar的高度,也就是说statusbar是全白的。。

解决办法:

  1. 自定义CustomInsetsFrameLayout
public class CustomInsetsFrameLayout extends FrameLayout{    private int[] mInsets = new int[4];    public CustomInsetsFrameLayout(@NonNull Context context) {        super(context);    }    public CustomInsetsFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) {        super(context, attrs);    }    public CustomInsetsFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {        super(context, attrs, defStyleAttr);    }    public final int[] getInsets() {        return mInsets;    }    @Override    protected final boolean fitSystemWindows(Rect insets) {        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {            // Intentionally do not modify the bottom inset. For some reason,            // if the bottom inset is modified, window resizing stops working.            // TODO: Figure out why.            mInsets[0] = insets.left;            mInsets[1] = insets.top;            mInsets[2] = insets.right;            insets.left = 0;            insets.top = 0;            insets.right = 0;        }        return super.fitSystemWindows(insets);    }}
  1. 设置属性
 android:windowSoftInputMode="stateVisible|adjustResize" android:fitsSystemWindows="true"

完美适配!

更多相关文章

  1. Android2.2 API 中文文档系列(2) —— EditText
  2. Android(安卓)TabLayout 浅显总结
  3. Android(安卓)关于获取摄像头帧数据
  4. Android(安卓)WebView的使用(一)
  5. 文章标题
  6. android anim 动画效果
  7. android Log.isLoggable方法的使用
  8. 自己编写Android手电筒,支持5.0
  9. android音频、视频、拍照基础操作

随机推荐

  1. Android使用KSOAP2调用WebService及正确
  2. android 弹出Dialog的时候播放声音!
  3. [转]五大布局对象---FrameLayout,LinearL
  4. [置顶] android 耳机按钮深层理解
  5. [android] Proguard代码混淆器如何排除指
  6. Android培训班(45)
  7. Android引入第三方jar包的方法
  8. Android学习10-----Android组件通信 (8)
  9. 桌面便签程序的实现详解和源码 (上)
  10. 对Android任务栈的理解(很乱,只是随便记下