Android Jar libraries

前端 未结 7 546
名媛妹妹
名媛妹妹 2020-12-12 20:23

How do you setup a project that can result in a jar library file that can be used for android? I want to create a custom library across all projects.

Few other quest

7条回答
  •  我在风中等你
    2020-12-12 21:13

    I asked myselft the same question: can I export and reuse a layout in Android. I tried the following: export a project with XML resources to a JAR file, and then try to access a layout through it's R.layout. Of course it didn't work, as R.layout.main was an integer, the same integer as was associated to the single layout (relative.xml) defined in the host project's R.layout.

    The Android SDK kompiles layout xml files into View resources, and as XML files in the included JAR file are not layout xml files, they are not compiled and no ID is associated to them in R.layout.

    If you want to export a layout from your project, then you should export it as XML, and import it to the new project as a layout resource, not as part of an external library.

    If you want to reuse layouts from a JAR, you have to create a sublcalss of a View, and build the layout from code. Than you can instantiate it and set the created instance as the View of the Activity, or add the instance to the View of your Activity.

提交回复
热议问题