今天在开发的时候,这个代码在源码中是能够看到的,可是在android 4.3手机上面会报错,具体错误信息和代码以下:
setBackgroundDrawable(context.getDrawable(R.drawable.coach_popou_window));
会报这个错误
java.lang.NoSuchMethodError:android.content.Context.getDrawable
查阅资料能够获得这个解释:
改为这样便可java
setBackgroundDrawable(ContextCompat.getDrawable(context,R.drawable.coach_popou_window))主要缘由是由于是版本不对,若是是android 5.0以上的手机是支持的Prior to android.os.Build.VERSION_CODES#JELLY_BEAN, this function would not correctly retrieve the final configuration density when the resource ID passed here is an alias to another Drawable resource. This means that if the density configuration of the alias resource is different than the actual resource, the density of the returned Drawable would be incorrect, resulting in bad scaling.