当只有一个建议时,AutoCompleteTextView 建议隐藏在键盘下方

AutoCompleteTextView suggestion hides under keyboard when there is only one suggestion

我在我的 Android 项目中使用 AutoCompleteTextView,除以下内容外,几乎所有内容都按预期工作:

当我只有一个建议显示时,这个建议隐藏在软键盘下。但是当我有不止一个建议时,它们就会出现在软键盘上方(但遗憾的是不在我的 AutoCompleteTextView 上方)并且我可以看到所有这些建议并滚动浏览它们(如果有很多)。

我尝试修改 android:dropDownHeight 但没有成功。我也尝试设置 android:windowSoftInputMode="adjustResize|adjustPan" 并且它有效(我可以看到所有建议,即使只有一个)但是它会扰乱我的布局并扭曲显示的所有内容。

是否可以强制下拉建议始终显示在 AutoCompleteTextView 上方?否则我怎么解决这个问题?

这里是 AutoCompleteTextView 的XML:

<AutoCompleteTextView
    android:id="@+id/autoCompleteTextView"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:maxLines="1"
    android:digits="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"
    android:ems="10"
    android:inputType="text"
    android:fontFamily="@font/poppins_bold"
    android:textColor="@color/colorPrimary"
    android:background="@drawable/backwithborder"
    android:padding="8dp"
    android:paddingLeft="12dp"
    android:paddingStart="12dp"
    android:maxLength="25"
    android:dropDownAnchor="@id/givePointsToText"
    android:layout_toRightOf="@id/pointsSpinner"
    android:layout_toEndOf="@id/pointsSpinner"
    android:layout_toLeftOf="@id/givePointsButton"
    android:layout_toStartOf="@id/givePointsButton"
    android:layout_centerVertical="true"
    android:dropDownWidth="match_parent"/>

将此添加到您的清单文件中:

android:windowSoftInputMode="adjustPan|adjustResize"

像这样:

  <activity
        android:name="com.example.adjustscroll.MainActivity"
        android:label="@string/app_name"
        android:windowSoftInputMode="adjustPan|adjustResize" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

我通过将 AutoCompleteTextView 移动到屏幕顶部来“解决”我的问题,这样建议下拉菜单只在一侧,下拉菜单和软键盘都有空间。

丑陋的解决方案,但这是我解决问题的唯一方法。