您的位置:首页 > 移动开发 > Android开发

Android 设置状态栏后adjustResize属性无效

2017-07-01 17:04 405 查看
这两天被这个问题搞得很焦灼,今天终于解决了,在这里把自己解决的办法分享一下;

这是之前碰到的问题





如截图所示,输入框被遮住了

之前试过AndroidBug5497Workaround这个类,但发现在有些手机上无法做到适配,于是又到处找,最后终于找到了一种方法。

首先在对应的Activity里面设置

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

//根据输入法调节view的移动

然后重写根布局

public class FullScreenLinearLayout extends LinearLayout {
private int[] mInsets = new int[4];

public FullScreenLinearLayout(Context context) {
super(context);
}

public FullScreenLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}

public final int[] getInsets() {
return mInsets;
}

@Override
protected final boolean fitSystemWindows(Rect insets) {

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
mInsets[0] = insets.left;
mInsets[1] = insets.top;
mInsets[2] = insets.right;
return super.fitSystemWindows(insets);
} else {
return super.fitSystemWindows(insets);
}
}
}


只重写了fitSystemWindows方法。

然后在根布局里面设置

android:fitsSystemWindows="true"

这个问题到这里就解决了。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: