Margin between SearchView and collapseIcon in toolbar

天涯浪子 提交于 2020-01-11 04:35:08

问题


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?

I've tried :

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

but this doesn't work.


回答1:


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

(To get the layout parameters use the 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;



回答2:


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


来源:https://stackoverflow.com/questions/41510337/margin-between-searchview-and-collapseicon-in-toolbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!