Я создал навигационное представление для своего приложения для Android, однако получаю следующую ошибку при попытке запуска и сбоя активности.
Я просмотрел похожие проблемы других пользователей, но я все еще не могу точно определить проблему.
Будем очень благодарны любой помощи.
Logcat также указывает на строку 60 файла task_list.java, которая является:
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>
список_задач.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'
@Swati Теперь я могу видеть панель навигации без ошибок, спасибо, как мне теперь показать меню навигации, но?
Думаю проблема в navigation_menu. Итак, теперь снова добавьте эту строку. И в свой item list добавьте элемент один за другим и проверьте, из-за чего генерируется item ошибка.
@Swati да, вы правы, я неправильно структурировал navigation_menu (что-то связанное с отсутствием второго меню в элементе), теперь все работает, как и должно быть, спасибо за вашу помощь!




Удалите строку ниже и запустите ее.
" <item name = "android:textColor">@color/black</item>"
Извините, @Aravind, это вызвало ту же ошибку после удаления указанной строки.
не могли бы вы добавить свой navigation_menu.xml
@Abr Я исправил проблему, см. комментарии в исходном сообщении вверху, и я предоставил ответ с обновлением navigation_menu.xml ниже. Буду признателен, если вы отметите приведенный ниже ответ как правильный и проголосуете, пожалуйста. Спасибо за ваш вклад.
Проблема возникла из 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>
попробуйте удалить эту строку
app:menu = "@menu/navigation_menu"и посмотрите, отображается ли навигация?