Android:键入时保持 TextInputEditText 在视图中

Android: Keep TextInputEditText in view when typing

我正在尝试创建一个包含几个 TextInputEditText 元素的 activity。它们位于页面下方大约一半的位置,导致它们在出现时被键盘覆盖。因此,我尝试在 AppManifest.xml 中使用 windowSoftInputMode="adjustPan" 来滚动屏幕,以便在键入时保持文本框可见。

然而,所有这方面的尝试似乎都失败了。下面是我正在使用的布局层次结构,跟进了一些我已经尝试过但无济于事的解决方案示例。

布局xml

<ScrollView
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillViewport="true"
    android:isScrollContainer="false">

    <android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.design.widget.TextInputLayout
            android:id="@+id/inputA"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/inputAText"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/inputB"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/inputBText"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

        </android.support.design.widget.TextInputLayout>

   </android.support.constraint.ConstraintLayout>

</ScrollView>

AndroidManifest.xml 片段

<activity
    android:name=".activities.MyActivity"
    android:windowSoftInputMode="adjustPan"
    android:screenOrientation="sensorPortrait"
    android:theme="@style/AppTheme.NoActionBar" />

尝试的解决方案

  1. windowSoftInputMode="adjustPan"添加到AppManifest.xml中的相关activity(我也根据其他Whosebug的建议尝试了adjustResizeadjustPan|adjustNothing
  2. ConstraintLayout 放在 ScrollView
  3. android:isScrollContainer="false"添加到所述ScrollView
  4. 重新创建布局文件,仅将 ConstraintLayoutTextInputEditText 限制在所述布局的底部
  5. TextInputEditText 更改为 EditText 并删除 TextInputLayout
  6. 已将 ConstraintLayout 更改为 RelativeLayout

对于应该是一个相当简单的实现,我不知所措。任何进一步的建议表示赞赏。如有必要,我很乐意提供更多代码示例。

找到问题了!在我的主题中,我声明了 <item name="android:windowTranslucentStatus">true</item>。出于某种原因,这破坏了 windowSoftInputMode="adjustPan",因此我删除了它。

为了让状态栏保持透明,我使用了<item name="android:statusBarColor">@color/transparent</item>

希望有一天有人会发现这很有用。