AutoCompleteTextView的弹出框显示在键盘后面。

3

我在我的应用程序中有一个 AutoCompleteTextView,放置在布局的底部。 当用户输入数据时,应该出现带有项目的建议弹出窗口。 在安卓三星设备上运行OS 6.0.1时,一切都按预期工作:

enter image description here

但是在Android 8.0.0上(LG设备和模拟器8.1.0),我没有看到这样的弹出窗口,我认为它由于某些原因在键盘后面显示(因为当我点击返回按钮时,什么也没有发生 - 弹出窗口处理了该事件,只有在第二个返回点击时键盘才消失):

enter image description here

我的自动完成文本视图:
 <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
  <LinearLayout ...
        <android.support.v7.widget.AutoCompleteTextView

                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="16dp"
                android:background="@drawable/thin_square_border"
                android:maxLines="3"
                android:minHeight="60sp"
                android:padding="12dp"
                android:paddingEnd="16dp"
                android:paddingStart="16dp"
                android:textColor="@color/charcoalgray"

                />
       </LinearLayout>

    </ScrollView>

我曾在上面的视图中尝试了dropDownAnchor,并使用android:dropDownHeight="wrap_content",但那没有帮助。
2个回答

1

我在Oreo和Pie中找到了适合我的解决方案。我将其添加到了我的片段中:

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

这似乎是Oreo引入的一个错误。希望这能对你有所帮助。

-1

你需要在自动完成小部件中设置 android:dropDownAnchor="@id/container_comment"


你能详细说明一下吗?id/container_comment是什么?你只是从别处复制/粘贴而不知道这段代码如何工作的吗? - zeeshan
抱歉,我忘记了。我使用自定义的自动完成类来实现提及功能。我会尽快编辑我的回答。 - Yudi karma

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接