Error inflating class android.support.design.widget.NavigationView Android NavigationView

0

Good evening everyone!    I'm trying to create an application with navigationView pwla the first time and I'm encountering problems at the time of the setContentView call (R.layout.activity_main); the application consists of the activity main calling some fragments according to the menu item clicked, so the error already happens at the beginning of the activity when trying to mount the xml: activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/dl_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.ramattecgmail.rafah.studying.Activitys.MainActivity">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />

    <FrameLayout
        android:id="@+id/frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </FrameLayout>

</LinearLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/nv_main"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    app:headerLayout="@layout/header_nav"
    app:menu="@menu/menu_nav" />

</android.support.v4.widget.DrawerLayout>

menu_nav.xml

<?xml version="1.0" encoding="utf-8"?>

<group android:checkableBehavior="single">
    <item
        android:id="@+id/gi_perfil"
        android:checked="false"
        android:title="@string/gi_perfil"/>

    <item
        android:id="@+id/gi_abrirA"
        android:checked="false"
        android:title="@string/gi_abrirA"/>

    <item
        android:id="@+id/gi_consultarA"
        android:checked="false"
        android:title="@string/gi_consulta"/>

    <item
        android:id="@+id/gi_avaliar"
        android:checked="false"
        android:title="@string/gi_avaliar"/>

    <item
        android:id="@+id/gi_email"
        android:checked="false"
        android:title="@string/gi_email"/>

    <item
        android:id="@+id/gi_config"
        android:checked="false"
        android:title="@string/gi_config"/>

    <item
        android:id="@+id/gi_sair"
        android:checked="false"
        android:title="@string/gi_sair"/>

</group>

header_nav.xml

<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.CircleImageView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/img_perfil"
    android:layout_width="@dimen/circle_image_header"
    android:layout_height="@dimen/circle_image_header"
    android:src="@drawable/profile"
    app:border_color="#FF000000"
    android:layout_marginLeft="@dimen/mrg_imagem_perfil"
    android:layout_marginStart="@dimen/mrg_imagem_perfil"
    android:layout_centerVertical="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"/>

<TextView
    android:id="@+id/tv_nome"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="left"
    android:text="Nome do usuario"
    android:textSize="@dimen/tam_text_perfil"
    android:textColor="#fff"
    android:textStyle="bold"
    android:paddingBottom="4dp"
    android:layout_above="@+id/tv_email"
    android:layout_alignLeft="@+id/img_perfil"
    android:layout_alignStart="@+id/img_perfil" />

<TextView
    android:id="@+id/tv_email"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="left"
    android:text="Email do Usuario"
    android:textSize="@dimen/tam_text_perfil"
    android:textColor="#fff"
    android:layout_marginBottom="@dimen/mrg_bot_tvemail"
    android:layout_alignParentBottom="true"
    android:layout_alignLeft="@+id/tv_nome"
    android:layout_alignParentStart="@+id/tv_nome" />

Style.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

app.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
     defaultConfig {
         applicationId "com.ramattecgmail.rafah.studying"
         minSdkVersion 15
         targetSdkVersion 26
         versionCode 1
         versionName "1.0"
         testInstrumentationRunner 
  "android.support.test.runner.AndroidJUnitRunner"
    }
   buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
    'proguard-rules.pro'
    }
  }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-
core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

//FireBase
//Google
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.firebase:firebase-auth:11.0.1'
compile 'com.google.android.gms:play-services-auth:11.0.1'
compile 'com.android.support:design:26.+'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.android.support:support-v4:26.+'
testCompile 'junit:junit:4.12'
}


apply plugin: 'com.google.gms.google-services'

Thank you!

    
asked by anonymous 31.08.2017 / 03:25

1 answer

2

If the error is occurring, as you said, when inflating the layout in setContentView(R.layout.activity_main) , it seems to me that it is because you have two views as parent in the layout ( LinearLayout and NavigationView ), when there should be only one. There also seems to be an error because there is no declaration of namespaces used xmlns:android="http://schemas.android.com/apk/res/android" and xmlns:app="http://schemas.android.com/apk/res-auto" . To create a NavigationView, you need a DrawerLayout as parent in the layout with the two views I've commented nested inside it, as follows:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar" />

        <FrameLayout
            android:id="@+id/frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </FrameLayout>

    </LinearLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/nv_main"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:headerLayout="@layout/header_nav"
        app:menu="@menu/menu_nav" />

</android.support.v4.widget.DrawerLayout>

UPDATE

In your header_nav.xml menu, you have android.support.v4.widget.CircleImageView , which exists, but can not be used by us developers. In the documentation for this class, it is written:

/**
 * Private class created to work around issues with AnimationListeners being
 * called before the animation is actually complete and support shadows on older
 * platforms.
 */

You can use an external library to create round ImageViews like this: RoundedImageView

    
31.08.2017 / 04:42