[英]No resource found that matches the given name (at 'headerLayout') in Xamarin.Android
I'm creating Android app using Xamarin for Android. 我正在使用Xamarin for Android创建Android应用。 I want to use in my app NavigationDrawer, so I downloaded and installed 'Android Design Library' from Xamarin Components Store.
我想在我的应用程序NavigationDrawer中使用,所以我从Xamarin Components Store下载并安装了“Android Design Library”。 Then I edited my layout for this:
然后我为此编辑了我的布局:
<?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"
android:id="@+id/drawerLayout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fitsSystemWindows="true">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/articlesListView" />
<android.support.design.widget.NavigationView
android:id="@+id/navView"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/navHeader"
app:menu="@menu/navMenu"/>
</android.support.v4.widget.DrawerLayout>
navHeader.axml: navHeader.axml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="192dp"
android:background="?attr/colorPrimaryDark"
android:padding="16dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:orientation="vertical"
android:gravity="bottom">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Username"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"/>
</LinearLayout>
and menu/navMenu.xml: 和menu / navMenu.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_home"
android:title="Home" />
<item
android:id="@+id/nav_messages"
android:title="Messages" />
<item
android:id="@+id/nav_friends"
android:title="Friends" />
<item
android:id="@+id/nav_discussion"
android:title="Discussion" />
</group>
<item android:title="Sub items">
<menu>
<item
android:title="Sub item 1" />
<item
android:title="Sub item 2" />
</menu>
</item>
</menu>
Unfortunately while compiling, I received following error: 不幸的是,在编译时,我收到以下错误:
C:\\Project\\Project\\File.axml: Error APT0000: No resource found that matches the given name (at 'headerLayout' with value '@layout/navHeader').
C:\\ Project \\ Project \\ File.axml:错误APT0000:找不到与给定名称匹配的资源(在'headerLayout'处,值为'@ layout / navHeader')。 (APT0000) (AppName) C:\\Projects\\Project\\File.axml(0,0): Error APT0000: No resource found that matches the given name (at 'menu' with value '@menu/navMenu').
(APT0000)(AppName)C:\\ Projects \\ Project \\ File.axml(0,0):错误APT0000:找不到与给定名称匹配的资源(在'menu'处,值为'@ menu / navMenu')。 (APT0000) (AppName)
(APT0000)(AppName)
Somebody knows how I may solved this problem? 有人知道我怎么解决这个问题?
Thank you in advance 先感谢您
I had the same issue. 我遇到过同样的问题。 I simply put lower case letters in the name of the header layout file and it worked.
我只是将小写字母放在标题布局文件的名称中,它就可以了。
Before (Failing with same error message): 之前(失败并显示相同的错误消息):
app:headerLayout="@layout/DrawerHeader"
After: 后:
app:headerLayout="@layout/drawerheader"
Named Your layout file and menu with the small letter. 使用小写字母命名您的布局文件和菜单。
app:headerLayout="@layout/drawerheader"
app:menu="@menu/drawermenu"
Had the same problem. 有同样的问题。 Guess it is a bug.
猜猜这是一个错误。 C# code addition (in OnCreate() method of your activity) of navigation header view and menu view works fine for me.
导航标题视图和菜单视图的C#代码添加(在您的活动的OnCreate()方法中)对我来说很好。 That is done with NavigationView methods InflateMenu and inflateHeaderView .
这是使用NavigationView方法InflateMenu和inflateHeaderView完成的 。
EDIT 编辑
First delete 先删除
app:headerLayout="@layout/navHeader"
and 和
app:menu="@menu/navMenu"
from your Navigation Drawer layout and insert 从您的导航抽屉布局和插入
navigationView = FindViewById<NavigationView>(Resource.Id.navView);
navigationView.InflateHeaderView(Resource.Layout.navHeader);
navigationView.InflateMenu(Resource.Menu.navMenu);
somewhere in onCreate() method of your activity in question. 在你所讨论的活动的onCreate()方法的某个地方。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.