【问题标题】:Eclipse Android plugin not listing attributes with auto-complete for custom componentEclipse Android 插件未列出自定义组件的自动完成属性
【发布时间】:2010-12-08 15:55:51
【问题描述】:

一般来说,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 属性以及我定义的自定义属性。

有什么想法吗?

【问题讨论】:

  • 当您执行自定义视图时,甚至普通属性都不起作用。我真的不知道为什么:(
  • 两个月前我问过几乎相同的问题,但我没有得到任何有意义的答复。希望这次对我们来说会更幸运=)
  • 你使用的是“Android xml”文件类型?

标签: android eclipse-plugin


【解决方案1】:

在带有 ADT v0.9.7 的 Eclipse helios 上,它也不适用于我

但是,它是可能的(感谢resources xml 文件和父类的自省)。 我查看了 ADT 源代码(我喜欢开源)(比预期的要长),我认为它应该可以工作。来自AndroidContentAssist 的方法computeAttributeProposals(...) 读取ElementDescriptor 中的属性,并且由于CustomViewDescriptorService,它们似乎应该为自定义控件正确初始化

【讨论】:

    【解决方案2】:

    我发现关闭所有属性视图并重新打开会导致显示我的自定义属性

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-12
      • 1970-01-01
      • 2012-05-21
      • 2013-01-10
      • 1970-01-01
      • 2014-03-25
      • 2011-09-18
      • 1970-01-01
      相关资源
      最近更新 更多