Mycroft Wong
Mycroft Wong

Reputation: 23

Toolbar menu item always in overflow

I'm trying to write a demo of Toolbar and there are two options android.widget.Toolbar and android.support.v7.widget.Toolbar. Because all of my Activities are extended android.app.Activity, so I have to use android.widget.Toolbar. But when i wanna use the android.support.v4.widget.DrawerLayout and bind a ActionBarDrawerToggle on it, I found that the constructor of ActionBarDrawerToggle is expect a android.support.v7.widget.Toolbar. I'm totally confused. If I wanna finish this work, I have to change all of my Activities to extend ActionBarActivity, but it have been deprecated by Google. And I found that if I don't use ActionBarActivity, the Toolbar's menu items are always in overflow even with attribute "always" and I renounce the use of ActionBarDrawerToggle.

    <item
        android:id="@+id/action_search"
        android:icon="@android:drawable/ic_menu_search"
        android:orderInCategory="70"
        android:title="@android:string/search_go"
        app:actionViewClass="android.widget.SearchView"
        app:showAsAction="always" />[![enter image description here][1]][1]

Upvotes: 1

Views: 262

Answers (1)

Joshua
Joshua

Reputation: 6241

You should use AppCompatActivity instead of ActionBarActivity to support android.support.v7.widget.Toolbar.

Do not forget to add this to gradle.

compile 'com.android.support:appcompat-v7:22.1.1'

Upvotes: 1

Related Questions