What to use instead of getResources().getColor() because this is now deprecated

In this blog,
I have talked about what to use instead of a deprecated function of getColor.
getResources().getColor(R.color.color_name) is deprecated in API level 23.
 
So, we can use getColor(int, Theme) instead.

Or

you can use the ContextCompat.getColor() which is part of the Support V4 Library (so it will work for all the previous API).

instead of

getColor method

Returns a color connected with a particular resource ID.

 

. . .

Comments (2)

Add Your Comment

  • Cryptonix
    Thanks this was very useful 🙂
  • Android Developer
    What’s the use of the theme, though?
  • css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close