当前位置:网站首页>'getDrawable(int)' is deprecated,getDrawable过时
'getDrawable(int)' is deprecated,getDrawable过时
2022-06-10 11:35:00 【yechaoa】
getDrawable(int)在API 21(5.0)已经过时了
5.0之后使用:
ContextCompat.getDrawable(context, R.drawable.your_drawable)例如:
imageView.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.icon));源码
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);
}
}可以看出也是做了高版本低版本兼容的
边栏推荐
- Day 2 linked list (simple)
- 如何编写产品营销策划方案
- After an error occurs in the source observable, it will be directly entered into the catchrror operator instead of the sequence in the pipe before entering the catchrror
- Flink CDC 在大健云仓的实践
- API如何检测安全配置是否有错误?
- 第 2 天 链表(简单)
- 为你推荐一款高效的IO组件——okio
- How can the team be dissolved...
- 远程解决win10上keyboard和chrome不work的两例问题(by quqi99)
- 时间轴、物流信息。你根本不需要StepView
猜你喜欢

图文,文字预训练方式长期学习ing。

好玩的人脸识别小软件

MySQL数据类型

zoom如何在加入会议时关闭microphone

Digital commerce cloud furniture industry supplier evaluation management system: improve the core competitiveness of furniture enterprises and realize digital collaborative management

Flutter socketio example

大型项目综合实训

Essential 5 determinants of linear algebra

About one-way linked list

SqlSessionFactory和SqlSession详解
随机推荐
IDEA自定义配置链接nacos
2022年Z-Wave生态系统状态报告
"Forget to learn again" shell Basics - 29. Awk built-in variables
redis 面经详解
“减负”,让“猪”可以飞得更高
The teaching staff at station B will teach you how to use the most complete record of the mask detection items of yolov5 (in-depth learning / target detection / pytorch)
87. (leaflet house) leaflet military plotting - straight arrow modification
图文,文字预训练方式长期学习ing。
LVS+Keepalived高可用群集
Privilege application permission configuration
从 0 开始构建研发高效能全栈式团队
In 2021, the revenue of China's electronic components will be the first, revealing the development path of precision and high quality of Tencent
Transfomer自实现与官方库
【管理知多少】独立冲突之外,你做不到
CLIP使用
《浅谈数组》
Sword finger position operation
shape颜色渐变、圆角、半圆角、边框、填充
[WIP] Openstack Masakari (by quqi99)
Flutter websocket example