getColorStateList已被弃用 [英] getColorStateList has been deprecated

查看:460
本文介绍了getColorStateList已被弃用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里遇到问题.我刚刚从sdk 22更新到了23,并且已弃用了先前版本的"getColorStateList()".

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

我的代码就是这样

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

较旧的"getColorStateList"是

The older "getColorStateList" was

getColorStateList(int id)

新的是

getColorStateList(int id, Resources.Theme theme)

如何使用主题变量?预先感谢

How do I use the Theme variable? Thanks in advance

推荐答案

Theme对象是用于设置颜色状态列表样式的主题.如果您不使用带有单独资源的特殊主题,则可以按以下方式传递null或当前主题:

The Theme object is the theme that is used to style the color state list. If you aren't using any special theming with individual resources, you can either pass null or the current theme as follows:

TextView valorslide; // initialize
SeekBar seekBar; // initialize
Context context = this;
Resources resources = context.getResources();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
    seekBar.setProgressTintList(resources.getColorStateList(R.color.bar_green, context.getTheme()));
    valorslide.setTextColor(resources.getColorStateList(R.color.text_green, context.getTheme()));
} else {
    seekBar.setProgressTintList(resources.getColorStateList(R.color.bar_green));
    valorslide.setTextColor(resources.getColorStateList(R.color.text_green));
}

如果您不关心主题,则可以传递null:

If you don't don't care about the theme, you can just pass null:

getColorStateList(R.color.text_green, null)

See the documentation for more explanation. Note, you only need to use the new version on API 23 (Android Marshmallow) and above.

这篇关于getColorStateList已被弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆