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

来源:互联网 发布:算法的乐趣 pdf 网盘 编辑:程序博客网 时间:2024/06/10 19:47

这两天被这个问题搞得很焦灼,今天终于解决了,在这里把自己解决的办法分享一下;

这是之前碰到的问题



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

之前试过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"
这个问题到这里就解决了。

阅读全文
0 0