Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move SearchView 's search Icon to the right side?

enter image description here

Here is my layout, using android.support.v7.widget.SearchView. I want to move the search icon to the right side,but I haven't found any method... `

<android.support.design.widget.AppBarLayout     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:theme="@style/AppTheme.AppBarOverlay">      <android.support.v7.widget.Toolbar         android:id="@+id/toolbar"         android:layout_width="match_parent"         android:layout_height="?attr/actionBarSize"         android:background="?attr/colorPrimary"         app:layout_scrollFlags="scroll|enterAlways|snap"         app:popupTheme="@style/AppTheme.PopupOverlay">          <android.support.v7.widget.SearchView             android:layout_width="wrap_content"             android:layout_height="wrap_content" />     </android.support.v7.widget.Toolbar>      <android.support.design.widget.TabLayout         android:id="@+id/tab_main_title"         android:layout_width="match_parent"         android:layout_height="wrap_content" /> </android.support.design.widget.AppBarLayout> 

`

after i click the icon,it will change to this layout enter image description here

like image 758
meunicorn Avatar asked Apr 28 '16 04:04

meunicorn


People also ask

How do I move my search icon to the right?

android:layoutDirection="rtl" this worked for me. Show activity on this post. In case you want to use SearchView outside of ActionBar in any other view (let's say for example ConstraintLayout ) you can use the approach posted on this site.

How do I use search view?

Android SearchView provides user interface to search query submitted over search provider. SearchView widget can be implemented over ToolBar/ActionBar or inside a layout. SearchView is by default collapsible and set to be iconified using setIconifiedByDefault(true) method of SearchView class.


1 Answers

you could try the layoutdirection. set it to "rtl"

android:layoutDirection="rtl" in your searchview xml:

<android.support.v7.widget.SearchView                         android:id="@+id/searchView"                         android:layout_width="wrap_content"                         android:layout_height="wrap_content"                         android:layout_alignParentRight="true"                         android:layout_marginRight="11.4dp"                         app:iconifiedByDefault="true"                         android:animateLayoutChanges="true"                         app:queryHint="@string/search_hint"                         app:queryBackground="@android:color/transparent"                         app:searchHintIcon="@drawable/empty_drawable"                         app:closeIcon="@drawable/close_x_icon"                         **android:layoutDirection="rtl"**                         app:searchIcon="@drawable/magnifying_glass"                         /> 

dont forget to put this in your manifest application tag:

 android:supportsRtl="true" 
like image 151
j2emanue Avatar answered Sep 22 '22 10:09

j2emanue