Я хочу использовать бургер-меню для своего приложения Android Studio, и я пытаюсь следовать этому руководству: https://github.com/codepath/android_guides/wiki/Фрагмент-Навигация-Ящик
И в моем файле activity_main.xml у меня есть эта ошибка:
Android resource linking failed
E:\Smoozy\Documents\Findcontent\app\src\main\res\layout\activity_main.xml:76:
error: resource menu/drawer_view (aka com.example.findcontent:menu/drawer_view) not found.
error: failed linking file resources.
Вот мой каталог файлов:https://imgur.com/a/8bqT9rY
Мой drawer_view.xml находится в папке моего макета, и я попытался удалить «меню» из оператора кода app:menu = "@menu/drawer_view"/>.
<!-- This DrawerLayout has two children at the root -->
<android.support.v4.widget.DrawerLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
xmlns:app = "http://schemas.android.com/apk/res-auto"
android:id = "@+id/drawer_layout"
android:layout_width = "match_parent"
android:layout_height = "match_parent">
<!-- The navigation drawer that comes from the left -->
<!-- Note that `android:layout_gravity` needs to be set to 'start' -->
<android.support.design.widget.NavigationView
android:id = "@+id/nvView"
android:layout_width = "wrap_content"
android:layout_height = "match_parent"
android:layout_gravity = "start"
android:layout_weight = "1"
android:background = "@android:color/white"
app:menu = "@menu/drawer_view"/>
<!-- This LinearLayout represents the contents of the screen -->
<FrameLayout
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:orientation = "vertical">
<!-- The ActionBar displayed at the top -->
<include
layout = "@layout/toolbar"
android:layout_width = "match_parent"
android:layout_height = "wrap_content" />
<!-- The main content view where fragments are loaded -->
<FrameLayout
android:id = "@+id/flContent"
app:layout_behavior = "@string/appbar_scrolling_view_behavior"
android:layout_width = "match_parent"
android:layout_height = "match_parent" />
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Это код, который пытается достичь этого:
public void selectDrawerItem(MenuItem menuItem) {
// Create a new fragment and specify the fragment to show based on nav item clicked
Fragment fragment = null;
Class fragmentClass;
switch(menuItem.getItemId()) {
case R.id.nav_first_fragment:
fragmentClass = FirstFragment.class;
getSupportFragmentManager().beginTransaction().replace(R.id.flContent, new FirstFragment()).commit();
break;
case R.id.nav_second_fragment:
fragmentClass = SecondFragment.class;
getSupportFragmentManager().beginTransaction().replace(R.id.flContent, new SecondFragment()).commit();
break;
case R.id.nav_third_fragment:
fragmentClass = ThirdFragment.class;
getSupportFragmentManager().beginTransaction().replace(R.id.flContent, new ThirdFragment()).commit();
break;
default:
fragmentClass = FirstFragment.class;
}
try {
fragment = (Fragment) fragmentClass.newInstance();
} catch (Exception e) {
e.printStackTrace();
}
// Insert the fragment by replacing any existing fragment
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.flContent, fragment).commit();
// Highlight the selected item has been done by NavigationView
menuItem.setChecked(true);
// Set action bar title
setTitle(menuItem.getTitle());
// Close the navigation drawer
mDrawer.closeDrawers();
}
// ...
Спасибо!
Спасибо! @ישואוהבאותך




Я думаю, вам нужно переместить файл «drawer_view.xml» в каталог «меню», но у вас его нет. Так что просто создайте, щелкните правой кнопкой мыши res, а затем щелкните новый -> новый каталог ресурсов, выберите тип ресурса меню и нажмите «ок». Обычно вы увидите папку меню.
Перейдите в res и щелкните правой кнопкой мыши «Создать»> «Каталог ресурсов Android».
Имя: меню
Перейдите в drawable и вырежьте файл 'drawer_view.xml' в папку меню
И измените путь в коде.
Надеюсь помочь Вам.
В этом случае приложение:меню = "@меню/ящик_просмотр"
Вам нужно добавить макет
drawer_viewв каталогres/menu.