有谁能告诉我android中setBackgroundResource(resourceid)
和setBackgroundDrawable(getResource().getDrawable(drawableid))
之间的区别是什么?
答案 0 :(得分:8)
您可以自己查看Android source code for the View class并发现差异很小!
public void setBackgroundResource(int resid) {
if (resid != 0 && resid == mBackgroundResource) {
return;
}
Drawable d= null;
if (resid != 0) {
d = mResources.getDrawable(resid);
}
setBackground(d);
mBackgroundResource = resid;
}
setBackground()
只需拨打setBackgroundDrawable()
...
public void setBackground(Drawable background) {
//noinspection deprecation
setBackgroundDrawable(background);
}