开发者

How make Android self components and use it from a jar library?

I'm trying to create an android component that can be easily added to android projects as a jar library.

For this, I had to create new xml attributes in "res/values/attr.xml" that I add to my graphic xml element using the path:

 xmlns:app="http://schemas.android.com/apk/res/com.component.mypackage"

Then I import this project as a jar library into another project. To create my graphic components in the new project, I must change the path below:

 xmlns:app="http://schemas.android.com/apk/res/com.mylibrary"

But the path is incorrect: the custom attributes are not found.

I managed to integrate the R file in the library jar and I could access it from my xml to declare a custom component like this:

<PreferenceScreen
  xmlns:android = "http://schemas.android.com/apk/res/android"
 xmlns:app = "http://schemas.android.com/apk/res/com.myLibraryPackage">

<com.myLibraryPackage.mySelfComponent
     android:title="Name"
     android:key="name"
     app:hintText="Input your name"
     android:dialogTitle="Your name "
     app:validator="com.myLibraryPackage.myValidatorClass" />

What is strange is that if I put my file attr.xml in resources of my project, it works, which means it find com.myLibraryPackage.mySelfComponent. In that case, why it can't find also com.myLibraryPackage ?

(I also tried replacing

xmlns:app="http://schemas.android.com/apk/res/com.myLibraryPackage"

by

xmlns:app="http://schemas.android.com/apk/res/com.myApplicationPackage"

but it still doesn't work)

I would have preferred to use a jar to facilitate its integration in a project !

Has anyone encountered a problem like this who cou开发者_StackOverflow社区ld help me?

Thank you.


I'm trying to create an android component that can be easily added to android projects as a jar library.

If you want reuse code and resources, it won't be possible to do it with a jar file. You'll need to convert your library to a library project.

Then I import this project as a jar library into another project. To create my graphic components in the new project, I must change the path below:

If you're using a library project, you'd still reference the custom attribute as if it were contained in the application (since android will merge all the resources together when the application is compiled):

xmlns:app="http://schemas.android.com/apk/res/com.component.mypackage"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜