Search code examples
androidandroid-layoutandroid-search

How to add right margin to searchView's searchIcon?


How can I add right margin to the searchview's searchicon? I can't seem to find any working options here.

enter image description here

<android.support.v7.widget.SearchView
                        android:visibility="visible"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:id="@+id/main_searchView"
                        app:defaultQueryHint="@string/search_titel"

                        android:paddingLeft="6.0dp"
                        android:paddingRight="6.0dp"
                        android:iconifiedByDefault="false"
                        android:maxWidth="1000000dp"
                        android:theme="@style/SearchViewStyle"

                        />

Solution

  • Try this:

    layoutParams.leftMargin = 0;
    

    it can also be solved using this i think:

    LinearLayout searchEditFrame = (LinearLayout) searchView.findViewById(R.id.search_edit_frame);
    ((LinearLayout.LayoutParams) searchEditFrame.getLayoutParams()).leftMargin = 0;