如何在SearchView中将搜索图标提示更改为右侧

时间:2017-11-19 01:31:10

标签: android xml android-layout searchview

我有这样的布局search.xml

<SearchView
                android:layout_margin="@dimen/size_8"
                android:iconifiedByDefault="false" // <--- always expand
                android:id="@+id/searchView"
                android:layout_width="match_parent"
                android:background="#fff"
                android:queryHint="@string/search"
                android:layoutDirection="rtl"
                android:layout_height="wrap_content"
                />

结果:

enter image description here

我想将搜索图标更改为右图,如图所示

enter image description here

如何实现我想要的?感谢。

2 个答案:

答案 0 :(得分:1)

<android.support.v7.widget.SearchView
   android:id="@+id/searchView"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:clickable="true"
   android:layout_marginEnd="@dimen/_20sdp"
   android:layoutDirection="rtl"/>

答案 1 :(得分:0)

我可以考虑这种方式,但它更像是一个hack-ish,它改变了你的java类中的以下内容:

searchView.setIconifiedByDefault(true);
searchView.setIconified(true);

然后,继续在工具栏的右侧/末端设置搜索图标图像,然后在用户点击搜索图标后将该搜索图标设置为可见:

searchIconImage.setVisibility(View.VISIBLE);
相关问题