3

I am trying to use ToolBar (Lollipop Widget) using android.support.v7 library.

But while running an app getting an error.

android.view.InflateException: Binary XML file line #7: Error inflating class Toolbar    

My main goal is to have a navigation drawer using toolbar.

This is the Layout file which i am using :

   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/frame_container1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >


<Toolbar android:id="@+id/toolbar"            <------ line #7
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/status" ></Toolbar>

<android.support.v4.widget.DrawerLayout 
    android:id="@+id/drawer_layout"
    android:layout_below="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF" >

    <!-- Framelayout to display Fragments -->
    <RelativeLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </RelativeLayout>
    <!-- Listview to display slider menu -->

    <ListView
        android:id="@+id/list_slidermenu"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:dividerHeight=".02dp"        
        android:background="#000000"/>

</android.support.v4.widget.DrawerLayout>

        </RelativeLayout>  

I am using following code :

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        adapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, new String[]{""});
        //mDrawerList.setAdapter(adapter);
         t=(Toolbar) findViewById(R.id.toolbar);

        //getActionBar().setDisplayHomeAsUpEnabled(true);
        //getActionBar().setHomeButtonEnabled(true);


        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
                R.string.app_name, // nav drawer open - description for accessibility
                R.string.app_name // nav drawer close - description for accessibility
        ) {
            public void onDrawerClosed(View view) {

                // calling onPrepareOptionsMenu() to show action bar icons
                //  invalidateOptionsMenu();
            super.onDrawerClosed(view);
            }

            public void onDrawerOpened(View drawerView) {


                super.onDrawerClosed(drawerView);
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);
    }

Please help.

amit singh
  • 1,407
  • 2
  • 16
  • 25
user3371398
  • 459
  • 1
  • 6
  • 19

1 Answers1

7

Use

<android.support.v7.widget.Toolbar  />

instead of

<Toolbar  />
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • 1
    I'm getting the exact same error, but I do have `` defined in my layout. Any other ideas? – Russell Stewart Oct 21 '14 at 22:57
  • Never mind. Seems to be working now. I did two things; I'm not sure which one fixed it: 1) I updated the android-support-v13.jar library in my `libs` folder (the one I was using was still from the previous SDK). 2) I changed XML from: `` to: ` ` – Russell Stewart Oct 21 '14 at 23:03
  • 2
    Also had this issue and realized after a while that I simply forgot to make MyActivity extend ActionBarActivity instead of Activity. Might help someone – MathieuMaree Oct 31 '14 at 15:18