Including Android Activities (and their layouts) in JAR files

旧巷老猫 提交于 2019-12-03 13:44:38

问题


I'm trying to write a library that can be shared as a JAR file. This library will include an Activity and I'd like to include the layout in the JAR. Since it doesn't seem possible to include resource files in a JAR and I don't want the end-users to have to include these files themselves I was thinking it would be a nice hack to include the XML as a String then manually inflate it. Does anyone know if this is possible? Any other ideas?


回答1:


Native layout XML files are converted to a binary form, and include resource IDs baked at build time.

However since all GUI elements can be instantiated at runtime, you could probably roll your own inflater with an XML parser and a bit of reflection.

It may be easier in your case just to build the activity view programatically.



来源:https://stackoverflow.com/questions/2576980/including-android-activities-and-their-layouts-in-jar-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!