【问题标题】:Error : Attribute already defined with incompatible format in "attrs.xml" in Xamarin.Android错误:属性已在 Xamarin.Android 的“attrs.xml”中以不兼容的格式定义
【发布时间】:2019-04-11 10:28:14
【问题描述】:

我正在使用 Xamarin 开发我的应用程序。 我对 UWP 和 iOs 等其他平台没有任何问题。

但是当我尝试构建 Android 应用时,我收到以下错误:

Errors shown in Visual Studio 2017

所有这些错误都是指下面显示的“attrs.xml”文件:

    <?xml version="1.0" encoding="UTF-8"?>
<resources>
   <declare-styleable name="DrawableStates">
      <attr name="state_indeterminate" format="boolean" />
   </declare-styleable>
   <declare-styleable name="SfCheckBox">
      <attr name="isthreestate" format="boolean" />
      <attr name="cornerradius" format="float" />
      <attr name="checked" format="enum">
         <enum name="unchecked" value="0" />
         <enum name="indeterminate" value="1" />
         <enum name="checked" value="2" />
      </attr>
   </declare-styleable>
   <declare-styleable name="SfSegmentedControl">
      <!--        The selected index of SfSegmentCondrol-->
      <attr name="segmentSelectedIndex" format="integer" />
      <!--        The backcolor of SfSegmentCondrol-->
      <attr name="segmentBackColor" format="color" />
      <!--        The border color of SfSegmentCondrol-->
      <attr name="segmentBorderColor" format="color" />
      <!--        The border thickness of SfSegmentCondrol-->
      <attr name="segmentBorderThickness" format="string" />
      <!--        The color of SfSegmentCondrol-->
      <attr name="segmentColor" format="color" />
      <!--        The segment padding of SfSegmentCondrol-->
      <attr name="segmentedPadding" format="string" />
      <!--        The segment height of SfSegmentCondrol-->
      <attr name="segmentedHeight" format="string" />
      <!--        The segment width of SfSegmentCondrol-->
      <attr name="segmentedWidth" format="string" />
      <!--        The stroke thickness of SfSegmentCondrol-->
      <attr name="segmentStrokeThickness" format="string" />
      <!--        The corner radius of SfSegmentCondrol-->
      <attr name="segmentCornerRadius" format="string" />
      <!--        The position of SfSegmentCondrol-->
      <attr name="segmentPosition" format="enum">
         <enum name="top" value="0" />
         <enum name="bottom" value="1" />
         <enum name="fill" value="2" />
         <enum name="border" value="3" />
      </attr>
      <!--        The displaymode of SfSegmentCondrol-->
      <attr name="segmentDisplayMode" format="enum">
         <enum name="image" value="0" />
         <enum name="text" value="1" />
         <enum name="imagewithtext" value="2" />
      </attr>
   </declare-styleable>
</resources>

我的“attrs.xml”文件有问题吗? 我已经尝试清理和重建解决方案。删除并再次添加每个包,但错误仍然存​​在。

感谢您的帮助。

【问题讨论】:

    标签: xamarin xamarin.forms xamarin.android


    【解决方案1】:

    您是否像此链接一样使用过来自 Syncfusion 的 SfSegmentedControlhttps://help.syncfusion.com/xamarin-android/sfsegmentedcontrol/getting-started

    根据您的错误消息,有两个问题。

    Issue1segmentPosition segmentDisplayMode 有关。 我在SfSegmentedControl中找不到这些属性,你可以参考下面的截图。如果你想在attrs.xml中定义属性,SfSegmentedControl必须有这些属性。 解决方案:您可以自定义SfSegmentedControl 来添加这些属性。

    Issue2SfCheckBox相关,checked属性的格式是bool而不是enum像这个截图。

    解决方法:更改checked的格式

    【讨论】:

    • 感谢您的帮助 :) 实际上我没有在我的项目中使用 SfSegmentedControl,所以我只是清理了 atts.xml 中引用库的部分并且代码有效!再次感谢,祝您有美好的一天。
    猜你喜欢
    • 2018-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多