我试图理解后箭头和searchview
组件之间存在空间。我正在使用单独的activity
进行工具提示搜索。Android:在SearchView中最小化空间
我试图添加填充0到搜索视图,但没有成功。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/search_toolbar_color"
app:popupTheme="@style/AppTheme.PopupOverlay"
android:padding="0dp"
app:theme="@style/ThemeOverlay.AppCompat.ActionBar" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/search_results"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="3dp"
android:visibility="gone" />
</RelativeLayout>
</LinearLayout>
我创建的自定义搜索视图以满足我的要求,开放式键盘在输入搜索activity
,删除搜索图标,改变color
方案
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.search_menu, menu);
MenuItem searchItem = menu.findItem(R.id.action_search);
SearchManager searchManager = (SearchManager) this.getSystemService(Context.SEARCH_SERVICE);
if (searchItem != null)
{
_searchView = (SearchView) searchItem.getActionView();
}
if (_searchView != null)
{
_searchView.setSearchableInfo(searchManager.getSearchableInfo(this.getComponentName()));
_searchView.setQueryHint(getString(R.string.action_search));
_searchView.setIconifiedByDefault(false);
final SearchView finalSearchView = _searchView;
_searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener()
{
@Override
public void onFocusChange(View view, boolean hasFocus)
{
if (hasFocus)
{
// showInputMethod(view);
finalSearchView.onActionViewExpanded();
}
}
});
//remove the icon in searchView
ImageView searchViewIcon = (ImageView) _searchView.findViewById(android.support.v7.appcompat.R.id.search_mag_icon);
ViewGroup linearLayoutSearchView = (ViewGroup) searchViewIcon.getParent();
linearLayoutSearchView.removeView(searchViewIcon);
_searchView.setOnQueryTextListener(this);
_searchView.requestFocus();
}
return true;
}
更新:
通过使用视图层次结构检查工具栏布局后,我开始实现这一点ere是后箭头图像与搜索视图之间的某种appcompat textview。不幸的是,我仍然无法知道如何从那里删除它。
不幸的是它没有工作,有一些文本视图,在工具提示中占用一些空间。您可以在我的第一篇文章中看到我的更新 –
尝试用'SearchView'替换您的'Toolbar',它们使用带有负值的'paddingLeft'将'TextView'向左推 – GuilhermeFGL