首页 > 顶部toolbar被软键盘顶出

顶部toolbar被软键盘顶出

我的布局文件中edittext在下方,点击时软键盘会把该edittext遮盖,然后在manifest中设置了android:windowSoftInputMode="adjustPan"
这时候,整个布局被顶上去了,editext是没有被遮盖了,但是顶部的toolbar被顶出去了
该怎么设置才能使edittext不被隐藏,但toolbar也不被顶出去


这样:


<LinearLayout ... >
    <Toolar ... />
    <ScrollView ... >
        <Edittext ... />
        ... 
    </ScrollView>
</LinearLayout>

碰巧我在开发的过程中也遇到了这个问题
我的解决方案如下
1.在所需要的布局上添加入Scrollview

<ScrollView ... >
        <Edittext ... />
        ... 
</ScrollView>

2.如果有设置windowSoftInputMode="adjustPan" 取消该设置

如果此时发现不生效
3.在你的根布局的layout 下设置
android:fitsSystemWindows="true"
参考 http://stackoverflow.com/questions/7417123/android-how-to-adjust-layout-in-full-screen-mode-when-softkeyboard-is-visible

4.如果有部分机型发现状态栏布局变透明
参考 http://stackoverflow.com/questions/21092888/windowsoftinputmode-adjustresize-not-working-with-translucent-action-navbar
自定义了一个layout继承你的根layout。
重写fitSystemWindows方法,并且在根layout中声明 fitSystemWindows="true"

自定义布局

package com.meizu.mzbbs.widget;

import android.content.Context;
import android.graphics.Rect;
import android.os.Build;
import android.util.AttributeSet;
import android.view.WindowInsets;
import android.widget.RelativeLayout;

/**
 * Created by yangjingxuan on 16/6/15.
 */
public class SoftInputRelativeLayout extends RelativeLayout {

    private int[] mInsets = new int[4];

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

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

    @Override
    public WindowInsets computeSystemWindowInsets(WindowInsets in, Rect outLocalInsets) {

        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] = outLocalInsets.left;
            mInsets[1] = outLocalInsets.top;
            mInsets[2] = outLocalInsets.right;

            outLocalInsets.left = 0;
            outLocalInsets.top = 0;
            outLocalInsets.right = 0;
        }

        return super.computeSystemWindowInsets(in, outLocalInsets);

    }

    @Override
    public WindowInsets onApplyWindowInsets(WindowInsets insets) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
            mInsets[0] = insets.getSystemWindowInsetLeft();
            mInsets[1] = insets.getSystemWindowInsetTop();
            mInsets[2] = insets.getSystemWindowInsetRight();
            return super.onApplyWindowInsets(insets.replaceSystemWindowInsets(0, 0, 0,
                    insets.getSystemWindowInsetBottom()));
        } else {
            return insets;
        }
    }

}

给整个布局文件嵌套个ScrollView试试

【热门文章】
【热门文章】