Reputation: 243
I have this searchView and i want to move the search icon to the right(if possible)
my xml code:
<android.widget.SearchView
android:id="@+id/searchBox"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="7dp"
android:layout_below="@+id/header"
android:iconifiedByDefault="false"
android:background="@drawable/searchrectangle"
android:queryHint="@string/search_message">
</android.widget.SearchView>
Upvotes: 3
Views: 4624
Reputation: 21
I hope this work. It works for me.
android:layoutDirection="rtl"
Upvotes: 2
Reputation: 1009
If I am correct this is source for searchview https://android.googlesource.com/platform/frameworks/support.git/+/jb-mr2-release/v7/appcompat/res/layout/abc_search_view.xml .
From what it looks like, it uses linear layout and that mentioned icon is in front of text. That means there is not a nice way to put it on right side.
There are basically 3 options left, or at least which came to my mind.
use custom made layout with drawable and edittext, I think some of the effects can be done using CollapsibleActionView or/and custom animations (really depends on what you need from it)
use search view, style it without text icon:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:searchViewStyle">@style/appTheme.SearchView</item>
</style>
<style name="AppTheme.SearchView" parent="Widget.AppCompat.SearchView">
<item name="android:searchIcon" tools:targetApi="lollipop">@null</item>
</style>
And then basically add icon to right as a normal drawable.
Upvotes: 0