Android - Convert Color Resource to Color in Domain Object

Posted by Steve on Stack Overflow See other posts from Stack Overflow or by Steve
Published on 2010-03-30T12:44:56Z Indexed on 2010/03/30 12:53 UTC
Read the original article Hit count: 401

Filed under:

I have a domain object, where I created a method to return a text color based on the internal state of the domain object.

I have defined the colors in a color.xml file as resources. The problem I have now, is that I would like to return a Color object instead of a resource ID from the domain object method.

This way I can set the text color of a TextView by just calling

textView.setTextColor(domainObj.getTextColor())

since it expects a Color object and not a resource ID.

Currently, in an Activity, I can call

getResources().getColor(domainObj.getTextColorResource())

to convert a resource ID to a color, but I would like this done in the domain object and I am not sure how I would do this when I do not have access to the getResources method.

Are there any cleaner options than passing in a Resource object into the method, or domain object?

Thanks

© Stack Overflow or respective owner

Related posts about android