“android:dropDownAnchor”在安卓7.0(API 24)上无法使用

7
我已经创建了一个简单的AutoCompleteTextView,代码如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <AutoCompleteTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/query"
        android:dropDownAnchor="@id/dropdownDivider"
        android:dropDownWidth="match_parent"
        android:dropDownHeight="match_parent"
        android:inputType="text"
        android:android:imeOptions="actionSearch"/>
    <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:background="#ccc"
        android:id="@+id/dropdownDivider"/>
</LinearLayout>

下拉菜单应该位于自动完成文本视图和名为“dropdownDivider”的视图下方。它不应重叠在自动完成文本视图上。这是通过使用android:dropDownAnchor属性实现的。在API 23以下的版本中,这个方法完美地运行。
然而,在API 24(Android Nougat)中,下拉菜单会重叠在自动完成文本视图上,并占据整个屏幕。
我尝试过: - 用替换,但没有帮助。 - 尝试了一些答案,如thisthisthis等等,但都无法解决问题。
有什么想法吗?

我在Android 7.0上的AutocompleteTextViews也遇到了不同的行为。通常情况下,当点击时,UI会将所点击的视图滚动到屏幕顶部,然后在视图下方展开,但现在似乎下拉列表只出现在视图顶部,而UI不会自动滚动。 - buradd
1个回答

2

对于我来说,通过编程将下拉菜单高度设置为“wrap content”解决了问题。 autoCompleteTextView.setDropDownHeight(ViewGroup.LayoutParams.WRAP_CONTENT);


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