在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 use http://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: