如果要使用现有
tools:
在自定义视图中,只需将这些属性添加到
<declare-stleable>
:
<declare-styleable name="CustomView">
<!-- This will allow you to use tools:text attribute as well -->
<attr name="android:text"/>
</declare-styleable>
在自定义视图中,可以获得如下属性:
a.getText(R.styleable.CustomView_android_text)
现在您可以这样做:
<com.myapplication.CustomView
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Lorem ipsum"/>
这将允许您使用标准
工具:
自定义视图中的属性。如果您想定义自己的设计时属性,
I've written a small library that allows you to do that
.