一般用法
- 設(shè)置屬性:
android:windowSoftInputMode="stateVisible|adjustResize"
android:fitsSystemWindows="true"
以上做法會導(dǎo)致toolbar向下平移了statusbar的高度,也就是說statusbar是全白的孽查。。
解決辦法:
- 自定義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);
}
}
- 設(shè)置屬性
android:windowSoftInputMode="stateVisible|adjustResize"
android:fitsSystemWindows="true"
完美適配!