调用android的getColor()方法出现 java.lang.NoSuchMethodError: android.content.res.Resources.getColor

1.java.lang.NoSuchMethodError: android.content.res.Resources.getDrawable/getColor
或者 java.lang.NoSuchMethodError:android.content.Context.getDrawable/geColor

原因:Context类的getDrawable(res)/geColor(res)方法和Resources的getDrawable(res,theme)/getColor(res.theme)都是API21才添加的,低版本系统无法找到该方法所以报异常。

解决办法:
使用Resources的getDrawable(res),但是该方法在API22已废弃。
使用ContextCompat.getDrawable(context,res)。

 原文链接:https://blog.csdn.net/qq_22256565/article/details/52133565

猜你喜欢

转载自www.cnblogs.com/tangZH/p/9456987.html