Android: Getting attribute colors from specific theme returns black -
i'm using method color attributes
call
int color = fetchcolor( getbasecontext(), r.attr.prim );
method
public static int fetchcolor( context c, int id ) { typedvalue typedvalue = new typedvalue(); typedarray = c.obtainstyledattributes( typedvalue.data, new int[]{ id } ); int color = a.getcolor( 0, 0 ); a.recycle(); log.e( tag, "color: " + color ); return color; }
attributes
<attr name="prim" format="reference|color"/>
base theme
<item name="prim">@color/indigo500</item>
my theme
<item name="prim">@color/tealflat500</item>
result
the color returned 0 (black). why? have other colors work fine , there no difference other other colors being in greyscale (from white black).
edit: colors
<color name="indigo500">#3f51b5</color> <color name="tealflat500">#37474f</color>
i found solution worked me:
call
int color = fetchcolor( getbasecontext(), r.attr.prim );
method
public static int fetchcolor( context c, int id ) { int[] attrs = { id }; typedarray ta = c.obtainstyledattributes( r.style.mytheme, attrs ); int color = ta.getcolor( 0, color.black ); log.e( tag, "color: " + color ); return color; }
it answer question here on stackoverflow accidentally closed tab , can't find it. whoever came it, cheers mate.
Comments
Post a Comment