导航视图已创建,产生错误和崩溃活动

问题描述 投票:2回答:2

我为我的Android应用程序创建了一个导航视图但是当活动尝试启动和崩溃时我收到以下错误。

我看过其他用户类似的问题,但我仍然无法查明问题。

任何帮助将不胜感激。

logcat还指向task_list.java的第60行,它是:

setContentView(R.layout.navigation_drawer);

这最初指向一个基本的xml活动。

Binary XML file line #13: Binary XML file line #13: Error inflating 
class android.support.design.widget.NavigationView

Navigation_drawer.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/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">

<include layout="@layout/task_list"/>

<android.support.design.widget.NavigationView
    android:id="@+id/navigation_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:fitsSystemWindows="true"
    app:headerLayout="@layout/navigation_header"
    app:menu="@menu/navigation_menu">
</android.support.design.widget.NavigationView>

navigation_header.xml

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="160dp"
android:padding="16dp"
android:gravity="bottom"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:background="@drawable/background">


<de.hdodenhof.circleimageview.CircleImageView
    android:layout_width="56dp"
    android:layout_height="56dp"
    android:src="@drawable/accountimagecolor"
    android:scaleType="centerCrop"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/Alex"
    android:paddingTop="8dp"
    android:textAppearance="@style/Base.TextAppearance.AppCompat.Body1"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/emailAlex"
    android:padding="4dp"

android:textAppearance="@style/Base.TextAppearance.AppCompat.Body1"/>


</LinearLayout>

V21 / styles.xml

<resources>

<style name="AppTheme" 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="actionBarPopupTheme">@style/PopupTheme</item>
    <item name="android:navigationBarColor">@color/colorPrimary</item>
</style>

<style name="PopupTheme" parent="Theme.AppCompat.Light">
    <item name="android:background">@color/background</item>
    <item name="android:textColor">@color/black</item>
</style>

</resources>

task_list.Java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.navigation_drawer);

    toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle("Portstewart - SuperValu Task List");

    drawerLayout = findViewById(R.id.drawerLayout);
    navigationView = findViewById(R.id.navigation_view);

    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open_drawer, R.string.close_drawer);
    drawerLayout.setDrawerListener(toggle);

    toggle.syncState();

gradle这个

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:design:28.0.0'

implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-database:16.0.6'
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.firebaseui:firebase-ui-database:4.2.1'
implementation 'com.android.support:mediarouter-v7:28.0.0'
implementation 'de.hdodenhof:circleimageview:3.0.0'
}

apply plugin: 'com.google.gms.google-services'
java android navigationview
2个回答
1
投票

问题来自navigation_menu xml

最初,第二个菜单(高级选项)未包含在项目中。

这是正确的布局

<menu xmlns:android="http://schemas.android.com/apk/res/android">

<group android:checkableBehavior="single">

    <item
        android:title="Complete"
        android:id="@+id/complete">
    </item>
    <item
        android:title="In-Progress"
        android:id="@+id/inProgress">
    </item>
    <item
        android:title="Not Started"
        android:id="@+id/notStarted">
    </item>
</group>

<item android:title="Advanced Options">

    <menu>

        <item
            android:title="Other Items"
            android:id="@+id/other">
        </item>

    </menu>

</item>


 </menu>

0
投票

删除下面的行并运行它

" <item name="android:textColor">@color/black</item>"
© www.soinside.com 2019 - 2024. All rights reserved.