标签: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
我的主要目标是使用工具栏创建导航抽屉.
这是我正在使用的布局文件:
<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 />
标签:android,android-5-0-lollipop,inflate-exception 来源: https://codeday.me/bug/20190824/1713188.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。