I have an android SearchView like so -
<SearchView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:queryHint="Search the forum ..."
android:iconifiedByDefault="true"
android:id="@+id/search_forum"
android:layout_alignParentRight="true"
android:textColor="#aaa" />
This is not in my ActionBar, it's somewhere else in my activity.
I need the icon (the search icon) to stay on the right of my layout. On click it should expand into the SearchView (same behaviour as the ActionBar SearchView). I've tried android:layout_alignParentRight="true"
but the icon stays to the left.
Any help would be great :)
I found a solution for this problem. Just set layout Direction to "rtl" and icon will be in Right Side. Here is the code for my search view and it is working as intended.
<SearchView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layoutDirection="rtl"
android:iconifiedByDefault="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
I couldn't find an exact answer to this so I did this- Create an image view with search icon. Placed it on the right of my layout. On click, made the search view visible and set iconified false and requested focus for the search view.
I'd be so grateful if somebody could eventually help me find a proper solution for this.
If the question is still unanswered:
Just move the SearchView into a RelativeLayout, and align it to the right side of the parent:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.SearchView
android:layout_width="wrap_content"
android:id="@+id/searchView"
android:layout_alignParentRight="true"
android:layout_height="match_parent" />
The final result looks like this:
CardView with Linearlayout containing aligned SearchView
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With