错误充气类android.support.design.widget.NavigationView [英] Error inflating class android.support.design.widget.NavigationView
问题描述
我跟新组件 NavigationView 在支持设计库的教程,并能'T打通此错误消息:
错误充气类android.support.design.widget.NavigationView
我想每一个解决方法这里
<一个href="http://stackoverflow.com/questions/30547323/error-when-using-any-android-design-support-library-elements">Error使用任何Android的设计支持程序库元素时
但错误信息仍然存在。
XML
&LT; android.support.v4.widget.DrawerLayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:程序=http://schemas.android.com/apk/res-auto
机器人:ID =@ + ID / drawer_layout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:fitsSystemWindows =真正的&GT;
&LT; RelativeLayout的
机器人:layout_width =match_parent
机器人:layout_height =match_parent&GT;
&LT;包括布局=@布局/工具栏机器人:ID =@ + ID / mainToolBar/&GT;
&LT;片段机器人:名称=com.ais.cherry.fragment.LoginFragment
机器人:ID =@ + ID / loginFragment
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:layout_below =@ ID / mainToolBar/&GT;
&LT;片段机器人:名称=com.ais.cherry.fragment.WaterFallFragment
机器人:ID =@ + ID / mainFragment
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:layout_below =@ ID / mainToolBar/&GT;
&LT;片段机器人:名称=com.ais.cherry.fragment.SearchFragment
机器人:ID =@ + ID / searchFragment
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:layout_below =@ ID / mainToolBar/&GT;
&LT;片段机器人:名称=com.ais.cherry.fragment.ChatMainFragment
机器人:ID =@ + ID / chatMainFragment
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:layout_below =@ ID / mainToolBar/&GT;
&LT;片段机器人:名称=com.ais.cherry.fragment.ProfileFragment
机器人:ID =@ + ID / profileFragment
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:layout_below =@ ID / mainToolBar/&GT;
&LT; android.support.design.widget.NavigationView
机器人:ID =@ + ID / nav_view
机器人:layout_width =240dp
机器人:layout_height =match_parent
机器人:layout_gravity =开始
机器人:背景=@机器人:彩色/白
应用程序:itemTextColor =#212121
应用程序:headerLayout =@布局/ drawer_header
应用程序:菜单=@菜单/抽屉/&GT;
&LT; /android.support.v4.widget.DrawerLayout>
build.gradle
buildscript {
库{
mavenCentral()
行家{URLhttps://maven.fabric.io/public'}
}
依赖{
类路径io.fabric.tools:gradle:1.+
类路径com.android.tools.build:gradle:1.2.3
}
}
compileSdkVersion 22
buildToolsVersion22.0.1
defaultConfig {
的applicationIDcom.ais.cherry
的minSdkVersion 16
targetSdkVersion 22
multiDexEnabled真
renderscriptTargetApi 22
renderscriptSupportModeEnabled真
}
依赖{
编译com.android.support:appcompat-v7:22.2.0
编译com.android.support:support-v4:22.2.0
编译com.android.support:design:22.2.0
编译com.android.support:recyclerview-v7:22.2.0
}
项目build.gradle
buildscript {
库{
jcenter()
}
依赖{
类路径com.android.tools.build:gradle:1.2.3
}
}
styles.xml
&LT; XML版本=1.0编码=UTF-8&GT?;
&LT;! - 基本应用主题。 - &GT;
&LT;样式名称=AppTheme父=AppTheme.Base&GT;
&LT; /风格&GT;
&LT;样式名称=AppTheme.Base父=Theme.AppCompat.Light.NoActionBar&GT;
&LT;项目名称=机器人:windowActionBarOverlay&GT;真&LT; /项目&GT;
&LT;项目名称=机器人:windowActionModeOverlay&GT;真&LT; /项目&GT;
&LT;项目名称=机器人:actionModeStyle&GT; @风格/ AppTheme.ActionModeStyle&LT; /项目&GT;
&LT;项目名称=机器人:windowActionBar&GT;假&LT; /项目&GT;
&LT;项目名称=windowActionBar&GT;假&LT; /项目&GT;
&LT;项目名称=windowNoTitle&GT;真&LT; /项目&GT;
&LT;项目名称=机器人:windowNoTitle&GT;真&LT; /项目&GT;
&LT;! - 支持库的兼容性 - &GT;
&LT;项目名称=windowActionBarOverlay&GT;真&LT; /项目&GT;
&LT;! - 动作条的颜色 - &GT;
&LT;项目名称=colorPrimary&GT;#E91E63&LT; /项目&GT;
&LT;! - 状态栏的颜色 - &GT;
&LT;项目名称=colorPrimaryDark&GT;#C2185B&LT; /项目&GT;
&LT;! - 窗口颜色 - &GT;
&LT;项目名称=机器人:windowBackground&GT; @色/白&LT; /项目&GT;
&LT;! - 动作条标题文本 - &GT;
&LT;项目名称=机器人:titleTextStyle&GT; @风格/ AppTheme.MyActionBarTitleText&LT; /项目&GT;
&LT;项目名称=colorAccent&GT;#9E9E9E&LT; /项目&GT;
&LT;项目名称=drawerArrowStyle&GT; @风格/ AppTheme.MyDrawerArrowStyle&LT; /项目&GT;
&LT;! - 颜色actionMenu - &GT;
&LT;项目名称=actionMenuTextColor&GT;#FFFFFF&LT; /项目&GT;
&LT;项目名称=机器人:actionMenuTextColor&GT;#FFFFFF&LT; /项目&GT;
&LT; - 安卓!textColorSecondary是菜单的颜色
溢图标(三纵点) - &GT;
&LT;项目名称=机器人:textColorPrimary&GT;#212121&LT; /项目&GT;
&LT;项目名称=机器人:textColorSecondary&GT;#FFFFFF&LT; /项目&GT;
&LT;! - 导航栏的颜色 - &GT;
&LT;项目名称=机器人:navigationBarColor&GT;#E91E63&LT; /项目&GT;
&LT;! - 状态栏的颜色 - &GT;
&LT;项目名称=机器人:statusBarColor&GT;#C2185B&LT; /项目&GT;
&LT; /风格&GT;
任何帮助将是AP preciated!
编辑 - 添加@菜单/抽屉和放大器; @菜单/ drawer_header和放大器;堆栈跟踪
drawer.xml
&LT;菜单的xmlns:机器人=http://schemas.android.com/apk/res/android&GT;
&LT;组机器人:checkableBehavior =单一&GT;
&LT;项目
机器人:ID =@ + ID / nav_first_fragment
机器人:图标=@可绘制/ home_view
机器人:检查=真
机器人:标题=@字符串/主/&GT;
&LT;项目
机器人:ID =@ + ID / nav_second_fragment
机器人:图标=@可绘制/ comment_view
机器人:标题=@字符串/聊天/&GT;
&LT;项目
机器人:ID =@ + ID / nav_third_fragment
机器人:图标=@可绘制/ user_view
机器人:标题=@字符串/ profile文件/&GT;
&LT;项目的android:标题=@字符串/搜索&GT;
&LT;菜单&gt;
&LT;项目
机器人:标题=@字符串/衣/&GT;
&LT;项目
机器人:标题=@字符串/裤/&GT;
&LT; /菜单&gt;
&LT; /项目&GT;
&LT; /组&gt;
&LT; /菜单&gt;
drawer_header.xml
&LT; LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:方向=垂直机器人:layout_width =match_parent
机器人:layout_height =192dp
机器人:背景=?ATTR / colorPrimaryDark
机器人:填充=16DP
机器人:主题=@风格/ ThemeOverlay.AppCompat.Dark
机器人:重力=底和GT;
&LT;的TextView
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:文本=@字符串/标题
机器人:文字颜色=@机器人:彩色/白
机器人:textAppearance =@风格/ TextAppearance.AppCompat.Body1/&GT;
&LT; / LinearLayout中&GT;
堆栈跟踪(其中只有一部分)
有抛出三个例外如下:所有指出的问题是通过的setContentView(布局)的路线在layout.xml引起
。 了java.lang.RuntimeException:无法启动活动ComponentInfo {com.ais.cherry / com.ais.cherry.activity.FirstActivity}:android.view.InflateException:二进制XML文件线#32:错误充气类android.support.design.widget.NavigationView
致:android.view.InflateException:二进制XML文件中的行#32:错误充气类android.support.design.widget.NavigationView
java.lang.reflect.InvocationTargetException:产生的原因
android.content.res.Resources $ NotFoundException:资源编号为0x0所致
我有类似的错误。 当我用
&LT;样式名称=AppTheme.Base父=Theme.AppCompat.Light.NoActionBar&GT;
&LT;项目名称=colorPrimary&GT;#673AB7&LT; /项目&GT;
&LT;项目名称=colorPrimaryDark&GT;#512DA8&LT; /项目&GT;
&LT;项目名称=colorAccent&GT;#00BCD4&LT; /项目&GT;
&LT;项目名称=机器人:textColorPrimary&GT;#212121&LT; /项目&GT;
&LT;项目名称=机器人:textColorSecondary&GT;#727272&LT; /项目&GT;
&LT; /风格&GT;
为我工作,当我删除了android:textColorPrimary和android:textColorSecondary主题项目
&LT;样式名称=AppTheme.Base父=Theme.AppCompat.Light.NoActionBar&GT;
&LT;项目名称=colorPrimary&GT;#673AB7&LT; /项目&GT;
&LT;项目名称=colorPrimaryDark&GT;#512DA8&LT; /项目&GT;
&LT;项目名称=colorAccent&GT;#00BCD4&LT; /项目&GT;
&LT; /风格&GT;
试着用一个非常简单的应用程序的主题,开始了工作。
编辑:
这教程帮助。 我的理解是,使用机器人:textColorPrimary要求的最低API级别21.使用相同的标记没有机器人采用的设计支持库。任何支持库部件将试图找到textColorPrimary项目,而不是机器人:textColorPrimary,如果没有找到它抛出上述错误相同
I followed a tutorial of new component NavigationView in Support Design Library and can't get through this error message :
Error inflating class android.support.design.widget.NavigationView
I tried every workaround here
Error when using any Android Design Support Library Elements
but error message still exists.
xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include layout="@layout/toolbar" android:id="@+id/mainToolBar" />
<fragment android:name="com.ais.cherry.fragment.LoginFragment"
android:id="@+id/loginFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/mainToolBar" />
<fragment android:name="com.ais.cherry.fragment.WaterFallFragment"
android:id="@+id/mainFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/mainToolBar" />
<fragment android:name="com.ais.cherry.fragment.SearchFragment"
android:id="@+id/searchFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/mainToolBar" />
<fragment android:name="com.ais.cherry.fragment.ChatMainFragment"
android:id="@+id/chatMainFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/mainToolBar" />
<fragment android:name="com.ais.cherry.fragment.ProfileFragment"
android:id="@+id/profileFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/mainToolBar" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/white"
app:itemTextColor="#212121"
app:headerLayout="@layout/drawer_header"
app:menu="@menu/drawer" />
</android.support.v4.widget.DrawerLayout>
build.gradle
buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.ais.cherry"
minSdkVersion 16
targetSdkVersion 22
multiDexEnabled true
renderscriptTargetApi 22
renderscriptSupportModeEnabled true
}
dependencies {
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:support-v4:22.2.0'
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
}
Project build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowActionModeOverlay">true</item>
<item name="android:actionModeStyle">@style/AppTheme.ActionModeStyle</item>
<item name="android:windowActionBar">false</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowNoTitle">true</item>
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
<!-- ActionBar color -->
<item name="colorPrimary">#E91E63</item>
<!-- Status bar color -->
<item name="colorPrimaryDark">#C2185B</item>
<!-- Window color -->
<item name="android:windowBackground">@color/white</item>
<!-- ActionBar title text -->
<item name="android:titleTextStyle">@style/AppTheme.MyActionBarTitleText</item>
<item name="colorAccent">#9E9E9E</item>
<item name="drawerArrowStyle">@style/AppTheme.MyDrawerArrowStyle</item>
<!-- color for actionMenu-->
<item name="actionMenuTextColor">#FFFFFF</item>
<item name="android:actionMenuTextColor">#FFFFFF</item>
<!-- android:textColorSecondary is the color of the menu
overflow icon (three vertical dots) -->
<item name="android:textColorPrimary">#212121</item>
<item name="android:textColorSecondary">#FFFFFF</item>
<!--Navigation bar color-->
<item name="android:navigationBarColor">#E91E63</item>
<!--Status bar color-->
<item name="android:statusBarColor">#C2185B</item>
</style>
Any help would be appreciated!
Edit -- add @menu/drawer & @menu/drawer_header & stacktrace
drawer.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_first_fragment"
android:icon="@drawable/home_view"
android:checked="true"
android:title="@string/main"/>
<item
android:id="@+id/nav_second_fragment"
android:icon="@drawable/comment_view"
android:title="@string/chat"/>
<item
android:id="@+id/nav_third_fragment"
android:icon="@drawable/user_view"
android:title="@string/profile"/>
<item android:title="@string/search">
<menu>
<item
android:title="@string/clothes"/>
<item
android:title="@string/pants"/>
</menu>
</item>
</group>
</menu>
drawer_header.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="192dp"
android:background="?attr/colorPrimaryDark"
android:padding="16dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:gravity="bottom">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/title"
android:textColor="@android:color/white"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"/>
</LinearLayout>
StackTrace (only part of them)
It thrown out three exceptions as below : all points out that the problems is caused by the line of "setContentView(layout)" at in layout.xml.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ais.cherry/com.ais.cherry.activity.FirstActivity}: android.view.InflateException: Binary XML file line #32: Error inflating class android.support.design.widget.NavigationView
Caused by: android.view.InflateException: Binary XML file line #32: Error inflating class android.support.design.widget.NavigationView
Caused by: java.lang.reflect.InvocationTargetException
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
I had similar error. When i use
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#673AB7</item>
<item name="colorPrimaryDark">#512DA8</item>
<item name="colorAccent">#00BCD4</item>
<item name="android:textColorPrimary">#212121</item>
<item name="android:textColorSecondary">#727272</item>
</style>
works for me when i remove the android:textColorPrimary and android:textColorSecondary theme items.
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#673AB7</item>
<item name="colorPrimaryDark">#512DA8</item>
<item name="colorAccent">#00BCD4</item>
</style>
Try working with a very simple App theme to start off with.
EDIT:
This tutorial will help. My understanding is that using "android:textColorPrimary" requires minimum api level 21. Using the same tag without "android:" uses the design support library. Any support library widget will try to find the "textColorPrimary" item instead of "android:textColorPrimary" and if it fails to find the same it throws the above mentioned error.
这篇关于错误充气类android.support.design.widget.NavigationView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!