【问题标题】:Margin between SearchView and collapseIcon in toolbar工具栏中 SearchView 和 collapseIcon 之间的边距
【发布时间】:2017-05-21 11:45:27
【问题描述】:

我正在尝试在Toolbar 上使用collapseIcon 来实现android.support.v7.widget.SearchView。一切正常,即SearchView 按预期工作,但我无法删除/减少SearchViewcollapseIcon 之间的填充,如所附屏幕截图所示。

关于如何做到这一点的任何想法?

我试过了:

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

但这不起作用。

【问题讨论】:

  • collapseIcon 在哪里?
  • 不相关,我已经在问题中提到我已经尝试了所有这些。无论如何,解决了这个问题。
  • @AshishRanjan 你是怎么解决这个问题的(下面提到的 leftMargin 方法不起作用)?
  • 您是否尝试将问题中提到的插图设置为零? @Bootstrapper,如果是,那么 SearchView xml 中可能发生了一些变化,您可以尝试自己查看 xml。或者您在实施解决方案时做错了什么。

标签: android searchview


【解决方案1】:

问题可以通过在布局参数中设置leftMargin = 0来解决,在SearchView中关联如下LinearLayout

(要获取布局参数,请使用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】:

我通过查看SearchView 使用的xml 文件设法解决了这个问题,因此可以通过更改leftMargin 值来删除/减少填充:

layoutParams.leftMargin = 0;

对于SearchView内的以下LinearLayout

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

【讨论】:

    猜你喜欢
    • 2015-11-06
    • 2015-11-02
    • 1970-01-01
    • 2015-10-07
    • 1970-01-01
    • 1970-01-01
    • 2012-11-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多