Margin between SearchView and toolbar collapseIcon

I am trying to implement android.support.v7.widget.SearchView with collapseIcon on Toolbar . Everything works fine, i.e. SearchView works as expected, but I cannot remove / reduce the indentation between SearchView and collapseIcon , as seen in the screenshot.

Any ideas on how I can do this?

SearchView

I tried:

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

but it does not work.

+2
source share
2 answers

I managed to solve the problem by looking at the xml file used by SearchView , so indents 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); 
+5
source

The problem can be solved by setting the leftMargin = 0 parameter in the layout options associated with the following LinearLayout in the SearchView :

(To get layout options, use getLayoutParams )

 LinearLayout searchEditFrame = (LinearLayout) searchView.findViewById(R.id.search_edit_frame); // Get the Linear Layout // Get the associated LayoutParams and set leftMargin ((LinearLayout.LayoutParams) searchEditFrame.getLayoutParams()).leftMargin = 0; 
+6
source

Source: https://habr.com/ru/post/1015086/


All Articles