简体   繁体   English

在Xamarin.Android中找不到与给定名称匹配的资源(在'headerLayout'处)

[英]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方法InflateMenuinflateHeaderView完成的

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.

相关问题 设置Xamarin.Forms-“找不到与给定名称匹配的资源...” - Setup Xamarin.Forms - “No resource found that matches the given name…” 如何修复Xamarin android c#中的“找不到与给定名称(在&#39;value&#39;处与值&#39;@ integer / google_play_services_version匹配)的资源” - How to fix“No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version)” in Xamarin android c# Xamarin-检索项目的父项时出错:找不到与给定名称&#39;Theme.AppCompat.Light.DarkActionBar&#39;匹配的资源 - Xamarin - Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar' 找不到与给定名称匹配的资源(在&#39;src&#39;处,值为&#39;@android:drawable / logo.png - No resource found that matches the given name (at 'src' with value '@android:drawable/logo.png 找不到与给定名称Styles.xml匹配的资源 - No resource found that matches the given name Styles.xml 如何在xamarin.android中设置imageView的资源? - how to set resource of imageView in xamarin.android? 没有找到与给定名称匹配的资源,我在哪里做错了? - No resource found that matches the given name, where I do something wrong? 来自类库和xamarin.android的资源 - Resource from class library and xamarin.android 如何处理 Xamarin.Android 中的“resource android:attr/android:progressBarStyleSmall not found”之类的错误? - How to deal with and error like “resource android:attr/android:progressBarStyleSmall not found” in Xamarin.Android? 找不到与给定名称匹配的资源 - No resource found that matches the given names
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM