我正在使用位于操作栏正下方的活动顶部的搜索查看,问题是建议显示在搜索视图上,因此用户无法看到键入的文字
<?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>
答案 0 :(得分:0)
通过将此视图添加到relativelayout的底部并将其设置为锚
来修复 <View android:id="@+id/fragment_map.dropDownAnchor" android:layout_below="@id/fragment_map.searchView" android:layout_width="match_parent" android:layout_height="0dp" />
答案 1 :(得分:0)
不知道官方回答甚至意味着什么。一位工作同事帮助了我,我想展示如何实现这一目标:
可以通过将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,就可以基本上更改锚点。