一般来说,Eclipse Android 插件可以按预期自动完成工作。但是,它不适用于我编写的自定义控件。基本上,除了默认的命名空间选项之外,自动完成列表是空的。
该控件继承自 Button 小部件并添加了一些额外的文本。我有几个额外的属性,我使用它们定义的:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="SubTextButton"
<attr name="sub_text" format="string" />
<attr name="sub_text_size" format="float" />
<attr name="sub_text_color" format="color" />
</declare-styleable>
</resources>
否则它会使用 Button 小部件的所有标准属性。
在布局文件中我指定了命名空间:
<?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.mycompany"
...
我使用控件:
<com.mycompany.SubTextButton
android:layout_width="@dimen/status_bar_button_w"
android:layout_height="@dimen/status_bar_button_h"
android:layout_alignParentRight="true"
android:background="@drawable/button_bg"
android:text="HCD"
android:textColor="@color/static_text"
android:textSize="@dimen/font_size_standard"
app:sub_text="SET"
app:sub_text_size="12.0"
/>
一切正常,但用户无法利用自动完成功能来查看哪些属性可用。理想情况下,我希望看到继承的 Button
属性以及我定义的自定义属性。
有什么想法吗?
最佳答案
在 Eclipse helios 和 ADT v0.9.7 上它对我也不起作用
但是,这是可能的(感谢 resources
xml 文件和父类的自省(introspection))。
我查看了(比预期更长的时间)ADT 源代码(我喜欢开源),我认为它应该可以工作。来自 AndroidContentAssist
的方法 computeAttributeProposals(...)
读取 ElementDescriptor
中的属性,由于 CustomViewDescriptorService
,它们似乎应该为自定义控件正确初始化
关于android - Eclipse Android 插件未列出自定义组件自动完成的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4389464/