3

I have an application that I now want to split part of off into a library project so I can re-use it in several other places. Among the stuff in there being re-used is a custom view, which uses code from this answer (http://stackoverflow.com/questions/1258275/vertical-rotated-label-in-android) with some adaptations I made to it. Anyway, the styleable resources don't work properly. The attr.xml looks like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
     <declare-styleable name="VerticalTextView">
        <attr name="text" format="string" />
        <attr name="textColor" format="color" />
        <attr name="textSize" format="dimension" />
        <attr name="rotateLeft" format="boolean" />
    </declare-styleable>
</resources>

and it's referenced in a layout file in the library project. I get the following error in Eclipse when trying to compile the main project:

[2010-12-20 23:29:38 - MyApp] C:\Library\res\layout\main.xml:124: error: No resource identifier found for attribute 'text' in package 'com.mydomain.mylibrary'

I'm puzzled. I've tried everything I can think of to get this to work, and I just haven't found the magic combination. How do I make styleable resources work inside of a library project?

2
  • i guess its too late but have u looked at this stackoverflow.com/questions/6471742/…
    – jsp
    Jul 19, 2011 at 23:18
  • It's a bit late for this project, but in the future, I'll give that a try. Thanks.
    – jjb
    Jul 20, 2011 at 3:42

2 Answers 2

6

The issue has been fixed in ADT 17: to use custom styleables defined in a library project, you have to use the http://schemas.android.com/apk/res-auto namespace, so, considering the example from the question:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto" ... >
    ...
    <com.foo.bar.VerticalTextView
        custom:textColor="#cafebabe"
        custom:rotateLeft="true"
        ... >
0
1

I have failed all attempts to get this working in a library package earlier this month and eventually gave up. To remedy the situation I just added the source files as 'linked' (still external from the project and shared) and this has been working for me.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.