【问题标题】:AutoCompleteTextView suggestion hides under keyboard when there is only one suggestion当只有一个建议时,AutoCompleteTextView 建议隐藏在键盘下
【发布时间】:2020-07-12 19:01:18
【问题描述】:

我在我的 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 dropdown android-softkeyboard autocompletetextview


    【解决方案1】:

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

    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>
    

    【讨论】:

    • 我试过了,它可以工作,但adjustResize 会扭曲屏幕上留下的所有内容。有没有办法解决这个问题?
    • 我不能说你还没有发布完整的布局文件。键盘占据全屏宽度。无法理解为什么只有“左”部分会失真。左边是什么?右边是什么?
    • 我的意思是“屏幕上剩余的一切都是扭曲的”,比如我的 imageViews。我通过将 AutoCompleteTextView 移动到屏幕顶部来“解决”我的问题。
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-02-18
      • 2015-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多