getResources()的getColor()是德precated [英] getResources().getColor() is deprecated

查看:228
本文介绍了getResources()的getColor()是德precated的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用: buildToolsVersion22.0.1 targetSdkVersion 22 在我的摇篮文件。

Using: buildToolsVersion "22.0.1" , targetSdkVersion 22 in my gradle file.

我发现有用的 getResources()的getColor(R.color.color_name)是德precated。

I found that the useful getResources().getColor(R.color.color_name) is deprecated.

我应该用什么代替呢?

推荐答案

它看起来像最好的方法是使用:

It looks like the best approach is to use:

ContextCompat.getColor(context, R.color.color_name)

这将选择棉花糖双参数法或pre-棉花糖方法适当。

This will choose the Marshmallow two parameter method or the pre-Marshmallow method appropriately.

这篇关于getResources()的getColor()是德precated的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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