今天给自定义控件设置drawable出现java.lang.NoSuchMethodError: android.view.View.setBackground,这是setBackground上下版本兼容型的问题;修改为如下代码即可:
public void setImage(Drawable drawable) { int sdk = android.os.Build.VERSION.SDK_INT; if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) { setBackgroundDrawable( drawable ); } else { setBackground( drawable ); } //setBackground(drawable); setType( TYPE_NONE ); }