今天幫助哥們解決了一個比較蛋疼的問題,就是在有的情況下會出現(xiàn)設置activity的windowSoftInputMode="adjustResize"時辈双,會失效的情況责掏。
歷盡千辛萬苦,終于在stackflow上找到解決方法湃望。在activity的根布局上添加fitsSystemWindows="true".
然后adjustResize就可以成功的起作用了拷橘。但是在這種情況下,你的titlebar會下移statusbar的高度的距離喜爷。所以就必須重寫一個layout繼承自你所使用的layout冗疮,并重寫其中的兩個方法,貼出代碼:
public class MyLinearLayout extends LinearLayout{
private int[] mInsets = new int[4];
public MyLinearLayout(Context context) {
super(context);
}
public MyLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public MyLinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@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);
}
@Override
public final WindowInsets onApplyWindowInsets(WindowInsets insets) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
mInsets[0] = insets.getSystemWindowInsetLeft();
Log.e("mInsets[0]",""+mInsets[0]);
mInsets[1] = insets.getSystemWindowInsetTop();
Log.e("mInsets[1]",""+mInsets[1]);
mInsets[2] = insets.getSystemWindowInsetRight();
Log.e("mInsets[2]",""+mInsets[2]);
return super.onApplyWindowInsets(insets.replaceSystemWindowInsets(0, 0, 0,
insets.getSystemWindowInsetBottom()));
} else {
return insets;
}
}
}
自己也記錄一下檩帐。