I'm try to understand from where there is space between the back arrow and the searchview
component. I'm using the separate activity
for searching with tooltip.
I tried to add padding 0 to the search view but without success.
<?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>
I created custom search view to meet my requirements, open keyboard while entering search activity
, remove the search icon and change the color
scheme
@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;
}
Update:
After inspecting the toolbar layout by using view hierarchy I come to realized there is some kind of appcompat textview between the back arrow image to the search view. Unfortunately I still can't manage to know how to remove it from there.