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:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/widget29"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/bg">
</RelativeLayout>
I try this in android 4+:
This helped me remove background color, hope it helps someone.
setBackgroundColor(Color.TRANSPARENT)
In addition to the excellent answers, if you want to achieve this via xml then you can add:
android:background="@android:color/transparent
to your view.
Best performance on this method :
Use this.
Use
setBackgroundColor(Color.TRANSPARENT)
to set the background as transparent, or usesetBackgroundColor(0)
. HereColor.TRANSPARENT
is the default attribute from color class. It will work fine.Try this
Check the setBackground functions in the RelativeLayout documentation