过时的getResources().getColor,和getResources().getDrawable
来源:互联网 发布:淘宝仓库招聘要求 编辑:程序博客网 时间:2024/05/29 17:11
解决方案:
利用ContextCompat中的方法
ContextCompat.getColor(getContext(),R.color.main_background);
ContextCompat.getDrawable(getContext(),R.drawable.ic_launcher);
源码为:
@ColorInt
public static final int getColor(Context context, @ColorRes int id) {
final int version = Build.VERSION.SDK_INT;
if (version >= 23) {
return ContextCompatApi23.getColor(context, id);
} else {
return context.getResources().getColor(id);
}
}
public static final Drawable getDrawable(Context context, @DrawableRes int id) {
final int version = Build.VERSION.SDK_INT;
if (version >= 21) {
return ContextCompatApi21.getDrawable(context, id);
} else if (version >= 16) {
return context.getResources().getDrawable(id);
} else {
// Prior to JELLY_BEAN, Resources.getDrawable() would not correctly
// retrieve the final configuration density when the resource ID
// is a reference another Drawable resource. As a workaround, try
// to resolve the drawable reference manually.
final int resolvedId;
synchronized (sLock) {
if (sTempValue == null) {
sTempValue = new TypedValue();
}
context.getResources().getValue(id, sTempValue, true);
resolvedId = sTempValue.resourceId;
}
return context.getResources().getDrawable(resolvedId);
}
}
- 过时的getResources().getColor,和getResources().getDrawable
- getResources().getDrawable()过时
- 过时的getResources().getColor()的替代方法
- 添加颜色getResources.getColor()过时的替换
- getResources().getColor()方法过时的替代方法
- Android中getResources().getDrawable() 过时的解决方法
- getResources().getDrawable()方法过时的替代方法
- Android中getResources().getDrawable() 过时的解决方法
- 解决Android中getResources().getColor()方法过时的问题
- Context#getResources().getDrawable()方法过时后的替代方法
- Context#getResources().getDrawable()方法过时后的替代方法
- getResources().getDrawable()方法过时后的替代方法
- Android getResources().getColor() 过时 替代方法
- Android getResources().getColor() 过时 替代方法
- getDrawable()和getColor()过时的解决办法
- getResources().getDrawable()过时问题 报错解决
- [问题解决]Android中getDrawable和getColor过时的替代方法
- getResources().getColor() deprecated
- Table Compression
- php最新Laravel框架5.3视频学习
- 各种 Java Thread State 第一分析法则
- 文件I/O实践(2) --文件stat
- 二十一、oracle pl/sql分类一 存储过程
- 过时的getResources().getColor,和getResources().getDrawable
- 自学DevExpress为Form表格换肤
- hive在0.13后已支持in与not in查询
- jsp Request获取url信息的各种方法
- iosiOS10 推送
- Unity Shader--- CG 标准函数库
- http 错误代码表
- Android---Data Binding使用入门
- KafkaConsumer一些概念解释(从官方文档整理而来)