android-6.0-23的getColor过时

来源:互联网 发布:狮子机平均分打法数据 编辑:程序博客网 时间:2024/05/16 14:06

getColor方法在6.0中已经过时:

@ColorInt@Deprecatedpublic int getColor(@ColorRes int id) throws NotFoundException {    return getColor(id, null);}


可以参考以下方法:

使用

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

This is the source code:

//源码

public static final int getColor(Context context, int id) {    final int version = Build.VERSION.SDK_INT;    if (version >= 23) {        return ContextCompatApi23.getColor(context, id);    } else {        return context.getResources().getColor(id);    }}

8 1
原创粉丝点击