Can someone tell me what is the difference between setBackgroundResource(resourceid) and setBackgroundDrawable(getResource().getDrawable(drawableid)) in android?
setBackgroundResource(resourceid)
setBackgroundDrawable(getResource().getDrawable(drawableid))
You can take a look at the Android source code for the View class and find out that the difference is very small!
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; }
And setBackground() just calls setBackgroundDrawable() ...
setBackground()
setBackgroundDrawable()
public void setBackground(Drawable background) { //noinspection deprecation setBackgroundDrawable(background); }