您可以在此处读取的属性位于 values\attrs.xml 中的 attrs.xml - 可以如下所示
<resources>
<declare-styleable name="bubbleview">
<!-- Color of the playground -->
<attr name="playgroundcolor" format="reference|color" />
<!-- Color of the canon arrow coming out of the top ball -->
<attr name="canoncolor" format="reference|color" />
<!-- Color of the score text -->
<attr name="scorecolor" format="reference|color"/>
</declare-styleable>
</resources>
enter code here
{
TypedArray l_typedArray =
getContext().obtainStyledAttributes(attrs,R.styleable.bubbleview);
m_scorecolor = l_typedArray.getColor(R.styleable.bubbleview_scorecolor,Color.RED);
m_canoncolor = l_typedArray.getColor(R.styleable.bubbleview_canoncolor,Color.BLUE);
l_typedArray.recycle(); // never forget this one!!!
}