自定义属性从另一个Android项目进口 [英] Custom attribute imported from another android project
问题描述
从我读别处中,编译器错误的自定义属性未找到资源标识符消失时,你改变了命名空间包含的项目领域:xmlns:SI =http://schemas.android.com/apk/lib/ com.my.base.project而不是的xmlns:SI =http://schemas.android.com/apk/res/com.my.base.project
这仍然没有解决实际读取自定义属性值的问题。从非工程背景。控制只是获取默认值。任何想法得到这个工作?
在我的应用程序在布局XML文件中使用此自定义属性,像这样:
<合并的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:SI =http://schemas.android.com/apk/lib/com.my.base.project>
< com.my.base.project.view.CustomView
SI:collapsedHeight =100dp>
< /com.my.base.project.view.CustomView>
< /合并>
从发行说明:
增加了对库中的自定义属性自定义视图支持。
使用自定义属性的布局必须使用命名空间URI
http://schemas.android.com/apk/res-auto 代替的URI
包括应用程序包名称。这个URI替换为应用程序
特定的一个在构建时。
块引用>他们将其标记为释放与SDK工具,修订17(2012年3月)。
From what I read elsewhere, the compiler error "No resource identifier found" for custom attributes goes away when you change the namespace for an included project to: xmlns:si="http://schemas.android.com/apk/lib/com.my.base.project" instead of "xmlns:si="http://schemas.android.com/apk/res/com.my.base.project"
This still doesn't solve the problem of actually reading the custom attribute's value. From a non project context. The control just gets the default value. Any ideas to get this working?
In my application I use this custom attribute like so in a layout XML file:
<merge xmlns:android="http://schemas.android.com/apk/res/android" xmlns:si="http://schemas.android.com/apk/lib/com.my.base.project"> <com.my.base.project.view.CustomView si:collapsedHeight="100dp"> </com.my.base.project.view.CustomView> </merge>
解决方案From the release notes:
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-auto instead of the URI that includes the app package name. This URI is replaced with the app specific one at build time.
They marked it as "released" with SDK Tools, Revision 17 (March 2012).
这篇关于自定义属性从另一个Android项目进口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!