错误膨胀类 android.support.design.widget.NavigationView [英] Error inflating class android.support.design.widget.NavigationView

查看:32
本文介绍了错误膨胀类 android.support.design.widget.NavigationView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在支持设计库中遵循了新组件 NavigationView 的教程并且无法通过此错误消息:

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

使用任何 Android 设计支持库元素时出错

但错误信息仍然存在.

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

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

任何帮助将不胜感激!

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

<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(只是其中的一部分)

抛出以下三个异常:都指出问题是由layout.xml中的"setContentView(layout)"那行引起的.

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

推荐答案

其实不是primarycolortext的问题,升级或者降级依赖.appcompat 库和设计支持库不匹配.

Actually it is not the matter of the primarycolortext, upgrading or downgrading the dependencies.This problem will likely occur when the version of your appcompat library and design support library doesn't match.

匹配条件示例

compile 'com.android.support:appcompat-v7:23.1.1' // appcompat library
compile 'com.android.support:design:23.1.1'       //design support library

这篇关于错误膨胀类 android.support.design.widget.NavigationView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆