我已经创建了一个自定义视图,它接受背景色剩余和阴影色剩余。但是当我转换资源ID以将它们存储在int变量中时。它给出的错误为
Expected a color resource id (R.color.) but received an RGB integer
下面是我的setter方法
@Override
public void setBackgroundColor(@ColorRes int backgroundResId) {
this.backgroundColor = ContextCompat.getColor(context, backgroundResId);
}
public void setShadowColor(@ColorRes int shadowColorId) {
this.shadowColor = ContextCompat.getColor(context, shadowColorId);
}
使用时会显示相同的错误
public void setBackgroundColor(@ColorRes int backgroundResId) {
this.backgroundColor = context.getResources().getColor(backgroundResId);
}