Search code examples
androidsearchview

Margin between SearchView and collapseIcon in toolbar


I'm trying to implement android.support.v7.widget.SearchView with a collapseIcon on the Toolbar. Everything works fine i.e, the SearchView is working as expected but I'm unable to remove/ reduce the padding between the SearchView and collapseIcon, as visible in the attached screenshot.

Any ideas on how can I do that?

SearchView

I've tried :

app:contentInsetStartWithNavigation="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
android:contentInsetLeft="0dp"
android:contentInsetStart="0dp"

but this doesn't work.


Solution

  • I managed to solve the problem by looking at the xml file that's used by SearchView, so the padding can be removed/reduced by changing the leftMargin value:

    layoutParams.leftMargin = 0;
    

    for the following LinearLayout inside the SearchView:

    LinearLayout searchEditFrame = (LinearLayout) searchView.findViewById(R.id.search_edit_frame);