美文网首页
Attribute "title" has

Attribute "title" has

作者: Felix_lin | 来源:发表于2018-06-11 10:46 被阅读18次

问题描述:

在开发过程中,会存在引用jar包时,自定义的attrs.xml中属性与jar包中属性冲突的情况:

碰到这个问题,我在网上查找了许多方法,包括stackoverflow等,好像没有查到很好的解决方式(汗!我的查找能力有待提高),在此我总结了下这次问题的解决办法:

  • 第一、更改自定义的属性名称,比如title --> title_self,但由于项目中引用该属性次数较多,且更改的话存在风险,故此方法不被采用
  • 第二、通过追溯jar包中的title引用,我发现jar包中有重复引用过title属性(以下为简单剪切代码)

      values文件下:
          <resources>
              <attr format="string" name="title"/>
              <declare-styleable name="head"><attr format="string" name="title"/>
              </declare-styleable>
          <resources>
    

    因此我们修改自定义属性,去除叼format格式宣称,仅保留 name="title"属性,测试APP运行正常且没有问题

      <declare-styleable name="top_nav">  
          <attr name="title" />
      </declare-styleable>  
    

相关文章

网友评论

      本文标题:Attribute "title" has

      本文链接:https://www.haomeiwen.com/subject/ribceftx.html