今天在Android Studio 1.2.2中编译代码时遇到Resources中getDrawable(int)已过期的警告信息:html
Warning:(133, 52) java: android.content.res.Resources中的getDrawable(int)已过期java
查看[1]可总结出如下信息:
android
Resources类中有两个方法在API level 22中被废弃:函数
废弃接口:Drawable getDrawable(int id)spa
替代接口:Drawable getDrawable(int id, Resources.Theme theme), 第二个参数@theme能够为空值.orm
或Context.getDrawable(int)htm
废弃缘由:在JELLY_BEAN(也就是Android 4.1版本)以前, 当这里传递的资源ID是另外一个Drawable资源的别名, 则该函数不能正确地获取到最终配置density。即别名资源(alias resource)的density配置不一样于实际资源的, 返回的Drawable对象的density将不正确, 这样缩放时将出错。对象
废弃接口:Drawable getDrawableForDensity(int id, int density)接口
替代接口:Drawable getDrawableForDensity(int id, int density, Resources.Theme theme)资源
检查getDrawable(int id)函数实现,当被调用时将输出下面警告信息并给出修改方案:
参考资料:
[1] Class Resources, http://developer.android.com/intl/zh-cn/reference/android/content/res/Resources.html