开发者

Android: Library projects and styleable resources

I have an application that I now want to split part of off into a lib开发者_开发问答rary 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?


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"
        ... >


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜