我有一个应用程序,我现在想将一部分分成一个库项目,所以我可以在其他几个地方重新使用它.重新使用的东西是一个自定义视图,它使用来自这个答案的代码(http://stackoverflow.com/questions/1258275/vertical-rotated-label-in-android),并对其进行了一些调整.无论如何,可调整资源不能正常工作.attr.xml看起来像这样:
<?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>
Run Code Online (Sandbox Code Playgroud)
它在库项目的布局文件中引用.尝试编译主项目时,我在Eclipse中收到以下错误:
[2010-12-20 23:29:38 - MyApp] C:\ Library\res\layout\main.xml:124:错误:找不到包'com.mydomain.mylibrary'中属性'text'的资源标识符
我很困惑.我已经尝试了所有我能想到的东西让它发挥作用,而我还没有找到神奇的组合.如何使可调整资源在库项目中工作?
该问题已在ADT 17中修复:要使用库项目中定义的自定义样式,您必须使用http://schemas.android.com/apk/res-auto命名空间,因此,请考虑问题中的示例:
<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"
... >
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2126 次 |
| 最近记录: |