2012-07-19 96 views
18

我知道如何创建视图自定义属性,例如:如何将文档添加到自定义属性?

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <declare-styleable name="SomeViewsCustomAttrs"> 
     <attr name="someAttr" format="dimension" /> 
     <attr name="anotherAttr" format="boolean" /> 
    </declare-styleable> 
</resources>  

我想知道如果有一种方法来添加文档,这些自定义的attrs。在编辑XML编辑器中的布局时,您可以获取描述attrs的工具提示。例如,如果您正在键入android:layout_width=它会给你以下信息,“指定视图的基本宽度。[尺寸,枚举]”

有没有办法为你自己的attrs提供?

感谢

+1

难道你有没有找到答案呢? – drewhannay 2013-06-17 17:04:53

+0

@drewhannay我放弃了寻找,还没有找到任何东西。 – cottonBallPaws 2013-06-18 16:23:38

回答

-1

你需要写在代码中的构造函数,然后将它们链接到XML。有关更多信息,请阅读this

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <declare-styleable name="SomeViewsCustomAttrs"> 
     <!-- Default highlight color for items that are pressed. --> 
     <attr name="colorPressedHighlight" format="color" /> 
     <!-- Default highlight color for items that are long-pressed. --> 
     <attr name="colorLongPressedHighlight" format="color" /> 
    </declare-styleable> 
</resources> 

并在Java文档这样您的视图链接到属性的Java源文件中(例如,从TextView):每个元素

3

添加XML注释

* See {@link android.R.styleable#TextView TextView Attributes}, {@link android.R.styleable#View View Attributes} 
+3

我没有关注你答案的第二部分(源文件)。 1)这是做什么的,它为什么重要? 2)在Java源文件中,您将这些Java Doc注释放在哪里?(在包的顶部?在类/文件声明中,在每种特定的方法?)? 3)为什么我会链接到'android.R.styleable'而不是'com.myproject.R.styleable'? – 2016-09-08 21:03:39

相关问题