NavigationView给出了一些错误(NavigationView gives some errors)

编程入门 行业动态 更新时间:2024-10-17 07:31:46
NavigationView给出了一些错误(NavigationView gives some errors)

我尝试为我的应用程序创建一个NavigationView ,如下所示:

<android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true">

<!-- Toolbar instead of ActionBar so the drawer can slide on top --> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="@dimen/abc_action_bar_default_height_material" android:background="?attr/colorPrimary" android:minHeight="?attr/actionBarSize" android:theme="@style/AppTheme.Toolbar"/> <!-- Real content goes here --> <FrameLayout android:id="@+id/content" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"/>

<!-- The navigation drawer --> <android.support.design.widget.NavigationView android:id="@+id/navigation" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" android:background="@android:color/background_dark" app:headerLayout="@layout/drawer_header" app:itemIconTint="@android:color/background_light" app:itemTextColor="@android:color/background_dark" app:menu="@menu/drawer"/> </android.support.v4.widget.DrawerLayout>

但是当它查找headerLayout时,它会向我headerLayout几个错误( drawer_header布局存在,也就是drawer xml)。

它说:

找不到包'xxx.xxx'中属性'headerLayout'的资源标识符

两种XML都存在,所以我不知道我做错了什么......

我正在使用Eclpse上的API 21进行编译。

为什么会发生这种错误?

编辑:请,我需要帮助...我仍然无法编译这个...我上传我的代码到Dropbox给任何可能想帮助我的人...仍然发现问题!

我试图添加appcompatv7库,但他们给我错误...现在我的项目不起作用...请帮忙!

链接到Dropbox这里

I tried to create a NavigationView for my application like this:

<android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true">

<!-- Toolbar instead of ActionBar so the drawer can slide on top --> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="@dimen/abc_action_bar_default_height_material" android:background="?attr/colorPrimary" android:minHeight="?attr/actionBarSize" android:theme="@style/AppTheme.Toolbar"/> <!-- Real content goes here --> <FrameLayout android:id="@+id/content" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"/>

<!-- The navigation drawer --> <android.support.design.widget.NavigationView android:id="@+id/navigation" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" android:background="@android:color/background_dark" app:headerLayout="@layout/drawer_header" app:itemIconTint="@android:color/background_light" app:itemTextColor="@android:color/background_dark" app:menu="@menu/drawer"/> </android.support.v4.widget.DrawerLayout>

But then it launches me several errors when looking for headerLayout (the drawer_header layout exists, also the drawer xml).

It says:

No resource identifier found for attribute 'headerLayout' in package 'xxx.xxx'

Both XML exist, so I don't know what I'm doing wrong...

I'm compiling using API 21 on Eclpse.

Why is this error happening??

EDIT: PLEASE, I need help... I still can't compile this... I uploaded my code to Dropbox to anybody who may want to help me... Still finding problems!

I've tried to add appcompatv7 libraries, but they give me errors... And now my project doesn't work... Please help!

Link to Dropbox here

最满意答案

您应该查看本教程的设计支持导航抽屉: http : //antonioleiva.com/navigation-view/本教程最后还有一个指向github项目的链接。

看完你的代码之后,我可以告诉你这样做了:

<DrawerLayout> <Toolbar/> <FrameLayout>your content here</FrameLayout> <NavigationView/> </DrawerLayout>

但这就是抽屉布局的工作原理:

<DrawerLayout> <LinearLayout> <Toolbar/> <FrameLayout>your content here</FrameLayout> </LinearLayout> <NavigationView/> </DrawerLayout>

简而言之 - > DrawerLayout应该只有两个孩子( 这里是官方文档 ,这样说)

Everything was solved when I upgraded to Android Studio...

Thanks all guys!

更多推荐

本文发布于:2023-07-06 07:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047402.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:出了   错误   NavigationView   errors

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!