How to change search icon hint to right in SearchView

Viewed 2533

I have layout search.xml like this

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

result :

enter image description here

I want to change search icon to right like picture bellow

enter image description here

How achieve like I want? Thanks.

2 Answers
<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"/>

One way I can think about this but it's more like a hack-ish which is changing the following in your java class:

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

Then, go ahead and set a search icon image on the right/end of your toolbar then set that search icon to visible once user clicks on the search icon:

searchIconImage.setVisibility(View.VISIBLE);
Related