'getDrawable(int)' is deprecated,getDrawable过时
来源:互联网 发布:女狙击手知乎 编辑:程序博客网 时间:2024/05/18 02:24
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); } }可以看出也是做了高版本低版本兼容的
阅读全文
1 0
- 'getDrawable(int)' is deprecated,getDrawable过时
- getDrawable(int) is deprecated
- getDrawable(int id) getColor(int id) is deprecate 已过时
- Andriod: The method getDrawable(int) from the type Resources is deprecated,一系列问题
- getDrawable过时替代方法
- Android getDrawable过时
- getResources().getDrawable()过时
- Android Studio问题解决系列—Resources中getDrawable(int)过时
- getDrawable过时的替代方法
- getDrawable过时的替代方法
- getDrawable()方法过时 替代
- getDrawable()方法过时 替代
- getDrawable过时的替代方法
- getDrawable过时的替代方法
- getDrawable过时的替代方法
- getDrawable()过时替换方案.md
- getResources().getDrawable(int id) 替代
- getDrawable,getColor 过时的替代方法
- WSN之串口
- iOS 安卓 服务器后台 公用的简单加密和解密
- MovieLens 《用Python进行数据分析》
- 【JavaWeb-30】SpringMVC原理、入门程序、参数传递
- 自定义VideoView实现视频画面的缩放
- 'getDrawable(int)' is deprecated,getDrawable过时
- git上传代码至github
- 代码优化, volatile关键字
- input.py
- 一个简单的Httpserver以及获取post提交的参数
- Android 关于arm64-v8a、armeabi-v7a、armeabi、x86下的so文件兼容问题
- Bat命令学习
- thinkphp关于考生信息相关统计
- Windows下Python3.5安装Numpy、Scipy