How to move SearchView 's search Icon to the right side?
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"
You can add search action in menu.xml like below:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<item
android:id="@+id/action_search"
android:icon="@mipmap/ic_search_white_24dp"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="ifRoom|collapseActionView" />
<item android:id="@+id/action_download"
android:title="@string/menu_action_download"
android:icon="@mipmap/ic_file_download_white_24dp"
android:orderInCategory="100"
app:showAsAction="always" />
</menu>
<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">
<RelativeLayout
android:id="@+id/not"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<android.support.v7.widget.SearchView
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</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>
You can do it programmatically
SearchView search = (SearchView) item.getActionView();
search.setLayoutParams(new ActionBar.LayoutParams(Gravity.RIGHT));