Remove background drawable programmatically in Android Remove background drawable programmatically in Android android android

Remove background drawable programmatically in Android


Try this

RelativeLayout relative = (RelativeLayout) findViewById(R.id.widget29);relative.setBackgroundResource(0);

Check the setBackground functions in the RelativeLayout documentation


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.


This helped me remove background color, hope it helps someone.setBackgroundColor(Color.TRANSPARENT)