Android 自定义控件No resource identifier found for attribute X in package X 和 res与res-auto的配置

在Android 自定义控件中需要指定命名空间 

一般我们的工程是这样指定的:xmlns:acptr="http://schemas.android.com/apk/res/你的包名"


但是在我们的工程为android.library=true (是library)的时候,就会报No resource identifier found for attribute X in package X

此时我们需要这样指定:xmlns:acptr="http://schemas.android.com/apk/res-auto" 

//让你的自定义控件自己去找res


那么问题来了 为什么会出现这种情况呢?

大家可以看看这个https://code.google.com/p/android/issues/detail?id=9656

这个里面提到了

“Added support for custom views with custom attributes in libraries. Layouts using custom attributes must use the namespace URI http://schemas.android.com/apk/res-autoinstead of the URI that includes the app package name. This URI is replaced with the app specific one at build time.”

“增加了对自定义视图支持,自定义属性。使用自定义属性布局必须使用命名空间URI http://schemas.android.com/apk/res-auto代替,其中包括应用程序包名的URI。这是URI与应用程序特定的一个在构建时更换。“


Upgrade to latest SDK & ADT version (fixed was released since r17) and usehttp://schemas.android.com/apk/res-auto as custom attributes' namespace URI, see Revisions for ADT 17.0.0:

升级到最新版本的SDK和ADT(固定是自R17)释放和usehttp://schemas.android.com/apk/res-auto自定义属性的命名空间URI,看到修订ADT 17.0.0:


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值