且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

getColorStateList已被弃用

更新时间:2023-12-05 10:45:04

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.