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

标签 android android-5.0-lollipop inflate-exception

我正在尝试通过 android.support.v7 库来使用 ToolBar (Lollipop Widget)。

但是在运行应用程序时出现错误。

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

我的主要目标是使用 toolbar 制作一个navigation drawer

这是我正在使用的布局文件:

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

我正在使用以下代码:

@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);
    }

请帮忙。

最佳答案

使用

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

代替

<Toolbar  />

关于安卓.view.InflateException : Binary XML file line #7: Error inflating class Toolbar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26463160/

相关文章:

java - 使用UsageEvents、UsageEvents.Event 和 MOVE_TO_FOREGROUND 计算每个应用一天内的使用次数

android - RuntimeException:自定义 TextView 加载字体无法制作原生字体或内存泄漏

android - 如何使用指定的 POST 参数打开 Android 浏览器?

android - CSS 媒体查询不反射(reflect)设备屏幕尺寸

android - 禁用安卓内置麦克风

android - 在 Android 中膨胀类 Button 时出错

java - android.view.InflateException : Binary XML file line #29: Error inflating class android. widget.Button

android - 使用 Android 应用内结算购买商品时(可能)出现未记录的错误

android - Google Nexus 5 上的手电筒

android - 键盘仅在 Lollipop 中覆盖 edittext 和 webview