0

我正在尝试NavigationViewDrawerLayout.

这是 XML 文件:

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

我已将这些添加到build.gradle

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

但它仍然显示

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)

环顾四周,有人说要添加app:textColor,试过了,但仍然无法启动

更新 :

这是我的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>
4

1 回答 1

1

尝试使用最新的依赖项编译

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

注意:始终尝试使用最新的依赖项

于 2016-02-02T09:35:13.590 回答