适用于 Android 的 .NET 警告 XA1005

示例消息

warning XA1005: Attempting basic type name matching for element with ID '@+id/text1' and type 'android.widget.TextView'
warning XA1005: If basic type name matching fails, please add a `xamarin:managedType` attribute to the element to specify the fully qualified managed type name of the element.

問题

启用 布局绑定和代码隐藏 时,将为具有 //*/@android:id 属性集的每个布局元素发出此警告,并为元素类型使用完全限定的名称。

例如, 将为 以下两个元素发出警告:

<android.widget.TextView
    android:id="@+id/text1" />
<Android.Widget.TextView
    android:id="@+id/text2" />

但是,对于仅使用不限定类名的元素, 不会 发出它,例如:

<TextView
    android:id="@+id/text1" />

“基本类型名称匹配”尝试确保任何完全限定的类型名称都是 C# 名称,而不是 Java 名称。 首先,它检查一个已知的 Java 命名空间与 C# 命名空间之间的映射简短列表,例如将 android.view 映射到 Android.Views。 对于任何剩余的命名空间,它会在.处拆分命名空间,并大写其每个部分。

解决方案

若要解决此警告,请更改每个元素以使用其未限定的 C# 类名称,或向每个元素添加一个 xamarin:managedType 属性以指定完全限定的 C# 名称。