I have a SearchView on my Toolbar and I want to change the icon of the default back button.
This is my toolbar:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/my_awesome_toolbar"
android:layout_width="fill_parent"
android:layout_height="?android:attr/actionBarSize"
app:titleTextColor="@android:color/black"
android:elevation="5dp">
</android.support.v7.widget.Toolbar>
And this is the layout of my SearchView:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/search"
android:title="@string/search"
app:icon="@drawable/ic_search_black_24dp"
android:icon="@drawable/ic_search_black_24dp"
app:showAsAction="always|collapseActionView"
android:maxWidth="50dp"
app:actionViewClass="android.support.v7.widget.SearchView"/>
</menu>
And this is how I create my option menu in my activity:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_search_team, menu);
SearchManager searchManager = (SearchManager)
getSystemService(Context.SEARCH_SERVICE);
searchMenuItem = menu.findItem(R.id.search);
searchView = (SearchView) searchMenuItem.getActionView();
ImageView searchClose = (ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_close_btn);
searchClose.setImageResource(R.drawable.ic_action_cancel_black);
searchClose.setVisibility(View.VISIBLE);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) searchClose.getLayoutParams();
params.gravity = Gravity.RIGHT;
searchClose.setLayoutParams(params);
searchClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Clear query
searchView.setQuery("", false);
//Collapse the action view
searchView.onActionViewCollapsed();
//Collapse the search widget
searchMenuItem.collapseActionView();
listview.setVisibility(View.GONE);
viewPager.bringToFront();
appBarLayout.setVisibility(View.VISIBLE);
}
});
for (TextView textView : findChildrenByClass(searchView, TextView.class)) {
textView.setTextColor(Color.BLACK);
textView.setHintTextColor(Color.BLACK);
}
searchView.setSearchableInfo(searchManager.
getSearchableInfo(getComponentName()));
searchView.setSubmitButtonEnabled(true);
searchView.setOnQueryTextListener(this);
return true;
}
The output of this is:
What I want is to hide this icon on the right or at least change the icon to the "x" image that I am defining as an ImageView in the code that I posted about my Activity.