Specifying Android project dependencies (in Eclipse)

前端 未结 5 806
一整个雨季
一整个雨季 2020-12-25 13:38

I have two Android projects, a \'library project\' containing a custom layout, and an \'application project\' containing an application which uses the layout.

Everyt

5条回答
  •  清酒与你
    2020-12-25 14:10

    Also, I got the attributes working, but not in the way it should work I think.

    You must use as the namespace in the element that uses your custom attributes, the namespace of your main app, not that of the library project. So, in your example, if you specify for the value of "xmlns:fnord" the namespace of your app project, it works.

    Also, when reading the custom attributes in your custom PredicateLayout(Context,AttributeSet) constructor, you must specify the app's namespace as well in calls to attributes.getAttributeValue().

    Which is a pain, since that code is in your library app which doesn't/shouldn't know about the app project it is used in. I worked around that by having the app call a static method ViewUtil.setAttributeNamespace(appNamespace) in my app's onCreate(), and the library's custom views use that namespace to retrieve the custom attributes. The attrs.xml file can then remain in the library project as well. Now the only ugly thing is that the layout XML must use the app's namespace on custom views, so you can't put those layout XML's in the library project.

提交回复
热议问题