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);
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);
相关文章推荐
- Android中getDrawable和getColor过时的替代方法
- getDrawable,getColor 过时的替代方法
- getDrawable,getColor 过时的替代方法
- 好用的 Android getDrawable过时的替代方法
- getDrawable()getColor()和方法过时的替代方法
- getDrawable过时的替代方法
- Context#getResources().getDrawable()方法过时后的替代方法
- Android中getResources().getDrawable() 过时的解决方法
- getDrawable过时的替代方法
- Android中getResources().getDrawable() 过时的解决方法
- Android getResources().getColor() 过时 替代方法
- getDrawable过时的替代方法
- Android getResources().getColor() 过时 替代方法
- getDrawable过时的替代方法
- Context#getResources().getDrawable()方法过时后的替代方法
- getDrawable过时替代方法
- (转)getDrawable过时的替代方法
- getDrawable()方法过时 替代
- getResources().getDrawable()方法过时的替代方法
- getDrawable过时的替代方法