What is the difference between setBackgroundResource and setBackgroundDrawable

Can someone tell me what is the difference between setBackgroundResource(resourceid) and setBackgroundDrawable(getResource().getDrawable(drawableid)) in android?

+7
android background view android-drawable
source share
1 answer

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() ...

 public void setBackground(Drawable background) { //noinspection deprecation setBackgroundDrawable(background); } 
+7
source share

All Articles