When compiling code in Android Studio 1.2.2 today, you encounter a warning message that getdrawable (int) is obsolete in resources:
Warning: (133, Java:android.content.res.Resources) getdrawable (int) is obsolete
View [1] To summarize the following information:
There are two methods in the resources class that are deprecated in API level 22:
Obsolete interface: drawable getdrawable (int id)
Alternate interface: drawable getdrawable (int id, resources.theme Theme), and the second parameter @theme can be a null value.
or context.getdrawable (int)
Discard Reason: before Jelly_bean (i.e. Android 4.1 version), when the resource ID passed here is an alias for another drawable resource, the function does not get the final configuration density correctly. that is, the density configuration of the alias resource is different from the actual resource, and the density of the returned Drawable object will be incorrect, so scaling will be an error.
Obsolete interface: drawable getdrawablefordensity (int id, int density)
Alternate interface: drawable getdrawablefordensity (int id, int density, resources.theme Theme)
Check the getdrawable (int id) function implementation and, when invoked, output the following warning message and give the modification scheme :
Resources:
[1] Class Resources, http://developer.android.com/intl/zh-cn/reference/android/content/res/Resources.html
Android Studio Problem Solving series 2-resources in getdrawable (int) obsolete