バック矢印とsearchview
コンポーネントの間にスペースがある場所を理解しようとしています。私はツールチップで検索するために別のactivity
を使用しています。Android:SearchViewのスペースを最小限にする
パディング0を検索ビューに追加しようとしましたが、成功しませんでした。検索activity
に入っている間、私は、私の要件を満たすために開いているキーボードをカスタム検索ビューを作成し
<?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>
、検索アイコンを削除し、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;
}
アップデート変更:
をビュー階層を使ってツールバーのレイアウトを検査した後、戻る矢印イメージと検索ビューとの間にある種のappcompat textviewがあります。残念ながら、私はそこからそれを削除する方法を知ることができません。
残念ながら、機能しませんでした。ツールチップにスペースを取っているようなテキストビューがあります。最初の投稿で私の更新を見ることができます –
'Toolbar'を' SearchView'に置き換えてみましょう。 'paddingLeft'を負の値で使って' TextView'を左に押します – GuilhermeFGL