在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: