getColorStateList has been deprecated

fkchaud picture fkchaud · Sep 2, 2015 · Viewed 17.1k times · Source

I'm having a problem here. I've just updated from sdk 22 to 23, and the previous version of "getColorStateList()" has been deprecated.

My code was like this

seekBar.setProgressTintList(getResources().getColorStateList(R.color.bar_green));
valorslide.setTextColor(getResources().getColorStateList(R.color.text_green));

The older "getColorStateList" was

getColorStateList(int id)

And new one is

getColorStateList(int id, Resources.Theme theme)

How do I use the Theme variable? Thanks in advance

Answer

user1354603 picture user1354603 · Sep 8, 2015

While anthonycr's answer works, it is a lot more compact to just write

ContextCompat.getColorStateList(context, R.color.haml_indigo_blue);