1

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]
0

1 Answer 1

1

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'
Sign up to request clarification or add additional context in comments.

1 Comment

I found it after posting this question, thanks anyway. All my questions work out when I use 'AppCompatActivity'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.