9

谁能告诉我androidsetBackgroundResource(resourceid)和in有什么区别?setBackgroundDrawable(getResource().getDrawable(drawableid))

4

1 回答 1

9

你可以自己看一下View类的Android源码,发现差别很小!

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);
}
于 2013-08-07T10:52:09.470 回答