I want to make the entire red circled area (which includes the title, the action bar's background, and the search icon) clickable, but my codes only allows only the search icon clickable.
I found the similar question here: I found the same problem in this question: How to increase the menuitem width in android while using Actionbar but the solution is not working for my codes.
Here is my menu xml:
<?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"
android:id="@+id/search_view_menu">
<item
android:id="@+id/action_search"
android:icon="@drawable/ic_search_dark"
app:actionViewClass="androidx.appcompat.widget.SearchView"
app:showAsAction="withText|ifRoom|collapseActionView"
android:title="Enter your item"
app:collapseIcon="@drawable/ic_close_dark"/>
</menu>
And here is my search java
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.example_menu, menu);
MenuItem searchItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) searchItem.getActionView();
searchView.setMaxWidth(Integer.MAX_VALUE);
searchView.setImeOptions(EditorInfo.IME_ACTION_DONE);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
adapter.getFilter().filter(newText);
return false;
}
});
return true;
}