Search code examples
androidandroid-navigationview

Android - Unable to inflate NavigationView


I'm trying to inflate NavigationView in Android inside a DrawerLayout.

Here's the XML file :

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

    <LinearLayout
        android:id="@+id/activity_newsfeed_wrapper"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:orientation="vertical" >

        <android.support.v7.widget.Toolbar
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/activity_newsfeed_toolbar"
            android:layout_width="match_parent"
            android:layout_height="@dimen/abc_action_bar_default_height_material"/>

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

        </FrameLayout>

    </LinearLayout>

    <android.support.design.widget.NavigationView
        android:id="@+id/activity_newsfeed_navigationView"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_gravity="end"
        app:headerLayout="@layout/drawer_header"
        app:menu="@menu/drawer"/>
</android.support.v4.widget.DrawerLayout>

I've added these in the build.gradle

compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:design:22.2.0'

But it still shows

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.somedomain.myproject/com.somedomain.myproject.Activities.HomeActivity}: android.view.InflateException: Binary XML file line #32: Error inflating class android.support.design.widget.NavigationView
                                                                          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2316)
                                                                          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2376)
                                                                          at android.app.ActivityThread.access$800(ActivityThread.java:147)
                                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                          at android.os.Looper.loop(Looper.java:135)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5253)
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at java.lang.reflect.Method.invoke(Method.java:372)
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
                                                                       Caused by: android.view.InflateException: Binary XML file line #32: Error inflating class android.support.design.widget.NavigationView
                                                                          at android.view.LayoutInflater.createView(LayoutInflater.java:633)
                                                                          at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
                                                                          at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
                                                                          at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
                                                                          at android.view.LayoutInflater.inflate(LayoutInflater.java:414)

Looked around and some said to add app:textColor, tried it but it still fail to launch

Update :

Here's my Style

<style name="NewsfeedTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="colorControlNormal">@color/textColor</item>
        <item name="colorControlActivated">@color/miBlue</item>
        <item name="android:textSize">18sp</item>
    </style>

Solution

  • Try to use latest dependencies compile

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

    Note: Always try to use latest dependencies