设置状态栏透明,当界面存在EditText时,在activity里面设置windowSoftInputMode:adjustResize 无效,软键盘依然会遮挡住EditText的焦点位置。
在activity的根布局上添加fitsSystemWindows="true",然后adjustResize就可以成功的起作用了。但是在这种情况下,你的titlebar会下移statusbar的高度的距离。所以就必须重写一个layout继承自你所使用的layout,并重写其中的两个方法。
public class CustomInsetLayout extends LinearLayout {
private int[] mInsets = new int[4];
public CustomInsetLayout(Context context) {
super(context);
}
public CustomInsetLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomInsetLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
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);
}
}
然后xml布局文件就类似如下形式:
<com.boohee.one.widgets.CustomInsetLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
//其它布局代码
</LinearLayout>
</ScrollView>
</com.boohee.one.widgets.CustomInsetLayout>
网友评论