Android SearchView建议显示在小部件上
我正在使用位于操作栏下方的活动顶部的searchview,问题是建议显示在searchview上,因此用户无法看到键入的文本Android SearchView建议显示在小部件上,android,Android,我正在使用位于操作栏下方的活动顶部的searchview,问题是建议显示在searchview上,因此用户无法看到键入的文本 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v7.widget.SearchView
android:id="@+id/fragment_map.searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.SearchView>
<RelativeLayout
android:layout_below="@id/fragment_map.searchView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map_container">
<!-- The map fragments will go here -->
</RelativeLayout>
</RelativeLayout>
通过将此视图添加到relativelayout的底部并将其设置为锚点进行修复
<View android:id="@+id/fragment_map.dropDownAnchor"
android:layout_below="@id/fragment_map.searchView"
android:layout_width="match_parent"
android:layout_height="0dp" />
甚至不知道官方的答案是什么意思。一位同事帮助了我,我想展示一下如何做到这一点: 可以通过编程方式将textview设置为AutoCompleteTextview: 假设您有一个xml格式的searchview,如下所示:
<android.support.v7.widget.SearchView
android:id="@+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginRight="10dp"
android:animateLayoutChanges="true"
android:paddingLeft="0dp"
app:closeIcon="@drawable/close_x_icon"
app:queryBackground="@drawable/search_bg_expanded"
app:searchHintIcon="@drawable/empty_drawable"
app:searchIcon="@null" />
然后在代码中执行以下操作:
val searchText = searchView.findViewById<TextView>(android.support.v7.appcompat.R.id.search_src_text) as? AutoCompleteTextView
searchText?.dropDownAnchor = searchView.id
因此,一旦您将其转换为AutocompleteTextView,您基本上可以更改锚定 通过将此视图添加到relativelayout的底部并将其设置为锚定来修复此问题。如果您的问题已修复,则将此作为答案发布,您可以接受它