Custom style - extracting attr color in code - works well since color duration is not #ffffffff

I have defined the attr color, set it in style and I am using the below code to use the value. Everything works fine as the color is different from #ffffffff (as per the code below, for any color defined in the style, the color variable gets the correct value, but for white the color value is -1). It seems like with my code the color value should be less than #ffffffff and I don't understand why.

this is attr definition:
<attr name="viewLvActive" format="color"/>

this is a custom style string:
<item name="@attr/viewLvActive">#ffffffff</item>

This is the code I am using to get this color value from my theme:

Resources.Theme theme = mCtx.getTheme();
TypedValue styleID = new TypedValue();
if (theme.resolveAttribute(R.attr.viewLvActive, styleID, true))
    color=styleID.data;
else
    color=-1;

      

Finally, I can live with the #fffffffe color, but still I would like to know where the error is.

+3


source to share


1 answer


What is the type of the variable color

? Because if he is int

, then -1 == #ffffffff

. If you check something like:

if (color == -1) {

      



you get true

for #ffffffff. int

- 32 bits and ARGB color fills it all. You cannot use a value like -1 (or any other value) to mean "no color".

0


source







All Articles