您的位置:首页 > 移动开发 > Android开发

Android的getColor,getDrawable过时的替代方法

2017-09-29 16:15 876 查看
问题

Android SDK
升级到 6.0(API23) 之后,getDrawable和getColor方法提示过时。

解决方法

getResources().getColor 替换成 ContextCompat.getColor

getResources().getDrawable 替换成 ContextCompat.getDrawable

例子

int colorInt = getResources().getColor(R.color.colorAccent);//返回的是color的int类型值:-49023
int colorInt2 = ContextCompat.getColor(this, R.color.colorAccent);//返回的是color的int类型值:-49023

Drawable drawable = getResources().getDrawable(R.mipmap.ic_launcher);
Drawable drawable2 = ContextCompat.getDrawable(this,R.mipmap.ic_launcher);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: