如何将搜索框中的搜索图标提示改为右侧显示?(涉及IT技术)

4
我有一个名为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

如何实现我想要的效果?谢谢。


你可以使用EditText替代SearchView,并设置右侧的drawable。 - Brijesh Kumar
2个回答

4
<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"/>

0

我可以想到的一种方法,但更像是一个hack-ish,即在您的Java类中更改以下内容:

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

接下来,在工具栏的右侧/末尾设置一个搜索图标,然后在用户单击搜索图标时将该搜索图标设置为可见:

searchIconImage.setVisibility(View.VISIBLE);

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