启动app应用的时候,在logcat中报这个错误java.lang.NoSuchMethodError: android.ImageView.setBackground 。
解决方法:是版本的问题 Jelly bean(4.1)版本以下 是不支持setBackground 。所以改为setBackgroundDrawable就可以了
activityAttention.setBackgroundDrawable(getResources().getDrawable(
R.drawable.activity_attention_normal));
但是改为setBackgroundDrawable会提示:The method setBackgroundDrawable(Drawable) from the type View is deprecated
解决方法:很明显方法被废弃了,把setBackgroundDrawable 换为setBackgroundResource即可。
且传入的参数直接是resource的id,无需再去通过ID获得View,更加方便。
activityAttention.setBackgroundResource(
R.drawable.activity_attention_selector);