ScrollView 导致工具栏在软键显示时扩展

ScrollView causing toolbar to extend when soft key shows

当 edittext 获得焦点(键盘弹出窗口)时,工具栏会扩展。

这个问题只出现在 pre-lollipop 上。

scrollview的使用方法正确吗?内部线性布局高度为环绕内容。

这里是activity

的代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.Toolbar 
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:fitsSystemWindows="true"/>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="fill_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <android.support.design.widget.TextInputLayout
            android:id="@+id/floatTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
            <EditText
                android:id="@+id/editTitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textCapSentences"
                android:nextFocusDown="@+id/noteContent"
                android:singleLine="true" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/floatTag"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <EditText
                android:id="@+id/editTag"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/tag"
                android:inputType="text"
                android:nextFocusDown="@+id/noteContent"
                android:singleLine="true" />
        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/floatNote"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <EditText
                android:id="@+id/noteContent"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/note"
                android:inputType="textMultiLine|textCapSentences" />
        </android.support.design.widget.TextInputLayout>
    </LinearLayout>
</ScrollView></LinearLayout>

在您的主程序中添加此配置 activity:- android:configChanges="orientation|screenSize|keyboard|keyboardHidden"

对我有用

将 fitsSystemWidows 更改为 false 的问题的答案是这样的 android:fitsSystemWindows="false"

第二期,删除android:elevation="4dp"

成为那样

你的整个 xml 文件应该是这样的

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <android.support.design.widget.TextInputLayout
        android:id="@+id/floatTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        <EditText
            android:id="@+id/editTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textCapSentences"
            android:nextFocusDown="@+id/noteContent"
            android:singleLine="true" />
    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:id="@+id/floatTag"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <EditText
            android:id="@+id/editTag"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/tag"
            android:inputType="text"
            android:nextFocusDown="@+id/noteContent"
            android:singleLine="true" />
    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:id="@+id/floatNote"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <EditText
            android:id="@+id/noteContent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/note"
            android:inputType="textMultiLine|textCapSentences" />
    </android.support.design.widget.TextInputLayout>
</LinearLayout>

最好在工具栏里面使用这个

android:layout_height="?attr/actionBarSize"

如果使用此代码

android:fitsSystemWindows="false"

工具栏重叠在状态栏下方。