我正在尝试制作自定义视图,并声明了如下的样式属性:
在CustomView的构造函数中,这些值可以通过以下方式获得:
视图可通过以下方式声明xml来使用:
我不明白在xml中定义的“黑色”颜色是什么意思,但当我将颜色设置为
:
<resources>
<declare-styleable name="NewCircleView">
<attr name="radius" format="integer"/>
<attr name="circlecolor" format="color"/>
</declare-styleable>
</resources>
在CustomView的构造函数中,这些值可以通过以下方式获得:
circleradius=a.getInt(R.styleable.NewCircleView_radius, 0);//global var
circlecolor=a.getColor(R.styleable.NewCircleView_circlecolor, 0);//global var and a is the typed array
视图可通过以下方式声明xml来使用:
<com.customviews.NewCircleView
android:layout_below="@id/thetext"
android:layout_width="match_parent"
android:layout_height="fill_parent"
app:radius="10000"
app:circlecolor="@color/black"<!--this is defined in colors.xml
/>
在自定义视图中,当我将绘制对象设置为:
thePaintObj.setColor(circlecolor);//circlecolor logs to an integer as expected
我不明白在xml中定义的“黑色”颜色是什么意思,但当我将颜色设置为
thePaintObj.setColor(Color.GRAY)
我在视图中获取颜色
有人可以告诉我可能做错了什么吗?
(注:如果您想让我发布更多代码,请告诉我)
编辑1:发布我的colors.xml。 看起来我的代码注释不清楚:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="red">#7f00</color>
<color name="blue">#770000ff</color>
<color name="green">#7700ff00</color>
<color name="yellow">#77ffff00</color>
<color name="black">#000000</color>
</resources>