SearchView not showing in toolbar - Android Lollipop

I have the following action on this toolbar:

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar_select_currency"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"/>

The menu is also declared in:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@+id/search"
      android:title="@string/search_currency"
      android:icon="@drawable/ic_action_search"
      android:showAsAction="collapseActionView|ifRoom"
      android:actionViewClass="android.support.v7.widget.SearchView"/>

</menu>

In this operation, I call:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.currency_selector_options_menu, menu);

    return true;
}

private void initActionBar() {
    // Initialize the Toolbar( this is the new ActionBar in Lollipop)
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_select_currency);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(getString(R.string.select_currency));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

Now my problem is that I do not get SearchView, as in a regular ActionBar, what I get is a regular menu. How can I get a regular SearchView?

+4
source share
1 answer

Use the application namespace:

xmlns:myapp="http://schemas.android.com/apk/res-auto"

myapp:showAsAction="always"

: Android sdk, android showAsAction, , ,

+6

All Articles