我已经为我的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();
渐变
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'
答案 0 :(得分: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>
答案 1 :(得分:0)
删除以下行并运行
" <item name="android:textColor">@color/black</item>"