getColor(int id) deprecated on Android 6.0 Marshmallow (API 23) -


the resources.getcolor(int id) method has been deprecated.

@colorint @deprecated public int getcolor(@colorres int id) throws notfoundexception {     return getcolor(id, null); } 

what can do?

starting android support library 23,
a new getcolor() method has been added contextcompat.

its description official javadoc:

returns color associated particular resource id

starting in m, returned color styled specified context's theme.


so, just call:

contextcompat.getcolor(context, r.color.your_color); 


you can check contextcompat.getcolor() source code on github.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -