I am trying to make a custom view and have declared the styled attributes like the below:-
<resources>
<declare-styleable name="NewCircleView">
<attr name="radius" format="integer"/>
<attr name="circlecolor" format="color"/>
</declare-styleable>
</resources>
in the constructor of the customview , these values are obtained like below:-
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
The view is used by declaring the xml as below:-
<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
/>
In the custom view when i set the paint object as :-
thePaintObj.setColor(circlecolor);//circlecolor logs to an integer as expected
I dont get the color-"black" defined in the xml
however when i set the color as
thePaintObj.setColor(Color.GRAY)
I get the color in the view
Can someone tell me what would I be doing wrong ?
(N.B:-If you want me to post more code , please let me know)
EDIT1:- Posting my colors.xml. Looks like it is not clear in my code comments:-
<?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>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…