【发布时间】:2012-08-22 15:01:31
【问题描述】:
我有一些自定义视图和自定义属性。我想定义我的视图使用哪些属性,以便 eclipse 可以将其用于内容辅助。
例如,我在 res/values 文件夹中声明了一个自定义 xml 属性:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="TagAttrs">
<attr name="spColor" format="color" />
</declare-styleable>
</resources>
而且我的布局文件使用了一个带有自定义属性的自定义视图:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.twp"
...
>
<com.twp.TestView
android:id="@+id/testView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:spColor="#FF00FF" >
...
</com.twp.TestView>
</LinearLayout>
如果我使用 android: 前缀,eclipse 会显示它为 LinearLayout(TestView 派生)提供的所有选项,但如果我使用 app: 前缀,它会在底部以红色显示“Element com.twp .TestView 不可用”。此外,如果我在 spColor 中尝试内容辅助,它会显示“内容辅助在当前位置不可用”。我想,既然我定义了“app”命名空间,它就能找到我的样式声明,并且至少知道 spColor 是一种颜色。
所以这只是 eclipse 的限制,还是我可以显式定义视图的自定义属性?
【问题讨论】:
标签: android-layout attributes content-assist graphical-layout-editor