我想为我的Android Studio应用程序使用一个汉堡菜单,而我正在尝试遵循本教程:https://github.com/codepath/android_guides/wiki/Fragment-Navigation-Drawer
在我的mage.exe
文件中,出现以下错误:
activity_main.xml
这是我的文件目录: https://imgur.com/a/8bqT9rY
我的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.
在我的布局文件夹中,我尝试从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>
谢谢!
答案 0 :(得分:0)
我认为您需要将“ drawer_view.xml”文件移动到“菜单”目录中,但是您没有,因此只需创建,右键单击res,然后单击“新建”->“新资源”目录,选择获取资源类型菜单,然后按“确定”。 通常,您现在会看到一个菜单文件夹
答案 1 :(得分:0)
转到res并右键单击新建> Android资源目录,确定
名称:菜单
转到drawable并将文件“ drawer_view.xml”剪切到菜单文件夹
并更改代码中的路径。
希望能对您有所帮助。