Zhambulable
Zhambulable

Reputation: 1093

How to set custom color in android

This is my res/values/color.xml

<resources>
    <color name="ColorPrimary">#FF5722</color>
</resources>

this is .java file

Color color = context.getResources().getColor(R.color.ColorPrimary); //Error
textView.setTextColor(color);

It's giving me an error. Required android.graphics.Color. Found int

How can I handle it?

Upvotes: 0

Views: 1823

Answers (1)

actaram
actaram

Reputation: 2058

The getColor method returns an int, but you try to store it in a Color object. I suggest you simply do this:

textView.setTextColor(context.getResources().getColor(R.color.ColorPrimary))

Since setTextColor takes an int in parameters.

Upvotes: 2

Related Questions