Reputation: 40464
Color color = new Color(context.getResources().getColor(R.color.bus_departures_hover));
As seen, I am attemping to create a Color object from a resource. This ain't working though!
Upvotes: 5
Views: 5281
Reputation: 1756
Kotlin way (API REQUIRED 26);
Color.valueOf(ContextCompat.getColor(context, R.color.color_white))
Upvotes: 1
Reputation: 1197
What has worked for me is:
Color c = new Color(ContextCompat.getColor(context, R.color.yourColor));
Upvotes: 10
Reputation: 344
It seems there's no API constructor that receives an int http://developer.android.com/reference/android/graphics/Color.html#Color()
You may use
int color= getResources().getColor(R.color.bus_departures_hover);
And use the color value in a setter.
Upvotes: 0