0

I've recently updated my apps to appcompat to v7:22.2.0. I have a searchview in the actionbar which was working fine before updating, but now the search field appears under the title when i press the search icon.

enter image description here

This is my code:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto">
<item
    android:id="@+id/search_participants"
    android:icon="@drawable/search_white"
    android:title="@string/search"
    app:actionViewClass="android.support.v7.widget.SearchView"
    app:showAsAction="collapseActionView|always"/>
</menu>

It still works, its fully functional, only the actionbar title is still displayed when using the SearchView. How can i prevent this from happening? Should i manually set the title to an empty string or is there a decent fix for this?

      @Override
  public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    mOptionsMenu = menu;
    if (mOptionsMenu != null) {
      menu.clear();
      mMenuInflater.inflate(R.menu.live_tracking_overview_menu, menu);


   mSearchItem = menu.findItem(R.id.search_participants);
  mSearchView = (SearchView) MenuItemCompat.getActionView(mSearchItem);
  mSearchView.setOnQueryTextListener(this);
  mSearchView.setQueryHint(getString(R.string.search));
  MenuItemCompat.setOnActionExpandListener(mSearchItem, new MenuItemCompat.OnActionExpandListener() {
    @Override
    public boolean onMenuItemActionExpand(MenuItem item) {
      showSearch();
          //i could hide the title here, but that's an ugly fix
      return true;
    }

    @Override
    public boolean onMenuItemActionCollapse(MenuItem item) {
      hideSearch();
      return true;
    }
  });
Michiel
  • 468
  • 3
  • 23
  • What do your showSearch and hideSearch functions do? Are you using the android.support.v7.widget.Toolbar? The code you've posted all works for me without any overlap. The problem exists somewhere else in your code. – blackcj Jun 19 '15 at 14:56
  • @blackcj Thanks for your help, i started looking in other places and figured it out. I have the toolbar in a CollapsingToolbarLayout: http://stackoverflow.com/questions/30742878/android-collapsingtoolbarlayout-and-searchview-text-overlapping – Michiel Jun 19 '15 at 15:22

0 Answers0