I want to remove the background drawable @drawable/bg programmatically.
Is there a way to do that?
Currently, I have the following XML in my layout:
setBackgroundResource(0) is the best option. From the documentation:
Set the background to a given resource. The resource should refer to a Drawable object or 0 to remove the background.
It works everywhere, because it's since API 1.
setBackground was added much later, in API 16, so it will not work if your minSdkVersion is lower than 16.