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 have a case scenario and I tried all the answers from above, but always new image was created on top of the old one. The solution that worked for me is:
This work for me:
setBackgroundResource(0)
is the best option. From the documentation:It works everywhere, because it's since API 1.
setBackground
was added much later, in API 16, so it will not work if yourminSdkVersion
is lower than 16.First, you have to write
then use this to show it
Try this code:
also this one works:
but be careful this one doesn't work: