android - 顶部toolbar被软键盘顶出
ringa_lee
ringa_lee 2017-04-17 16:10:27
[Android讨论组]
ringa_lee
ringa_lee

ringa_lee

全部回复(3)
大家讲道理

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

黄舟

这样:


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

碰巧我在开发的过程中也遇到了这个问题
我的解决方案如下
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;
        }
    }

}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号