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…
`

  • What is difference between 'debug.keystore' and 'release.keystore' in Android?
  • PhoneGap/Cordova Android get screen size after onDeviceReady
  • Run another AsyncTask in onPostExecute()
  • How to return an array from JNI to Java?
  • How to implement Flipboard ipad page turning animation for view flipper in android?
  • ImageView fit without stretching the image
  • <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

  • How can I handle empty response body with Retrofit 2?
  • How can I change language of my application
  • Libgdx weird modelling - depth error?
  • Change default package from com.example for Eclipse Android projects
  • Encode a series of Images into a Video
  • How to check if a Bitmap is empty (blank) on Android
  • 4 Solutions collect form web for “How to move SearchView 's search Icon to the right side?”

    You can do it programmatically

    SearchView search = (SearchView) item.getActionView();
        search.setLayoutParams(new ActionBar.LayoutParams(Gravity.RIGHT)); 
    

    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>
    

    Normal look
    Collapsed look

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

    Try this…It looks as you expect.Just add this line inside of SearchView Tag.

    android:gravity=”right”

    <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:gravity="right" />
    </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 Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.