Как создавать собственные компоненты Android и использовать их из библиотеки jar?

Я пытаюсь создать компонент Android, который можно легко добавить в проекты Android как библиотека jar.

Для этого мне пришлось создать новые атрибуты xml в «res / values ​​/ attr.xml», которые я добавляю к моему графическому элементу xml, используя путь:

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

Затем я импортирую этот проект как jar библиотеку в другой проект. 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 could help me?

Thank you.

10
задан alezhka 19 June 2012 в 17:20
поделиться