No resource identifier found for attribute 'headerLayout' in package错误解决方法


我在使用NavigationView这个控件的时候出现了以下的错误:

Error:(2) No resource identifier found for attribute 'headerLayout' in package 'com.example.administrator.learndrewablelayout'

Error:(2) No resource identifier found for attribute 'menu' in package 'com.example.administrator.learndrewablelayout'

Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'F:\Android\SDK\build-tools\24.0.2\aapt.exe'' finished with non-zero exit value 1


我的xml文件内容如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.NavigationView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/nv_main_menu"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:layout_gravity="start"
    android:clickable="true"
    app:headerLayout="@layout/activity_main_menu_head"
    app:menu="@menu/activity_main_menu_item">
</android.support.design.widget.NavigationView>


解决方法:

在build.gradle中添加如下:

compile 'com.android.support:design:24.1.1'


在我的build.gradle文件中是这样的

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:design:24.1.1'
    compile 'com.android.support:appcompat-v7:24.1.1'
}
 
 

添加上面那一句之后我的问题就可以解决了。。。。。。

猜你喜欢

转载自blog.csdn.net/qq_28468727/article/details/52958735