Emkey Emkey - 1 month ago 23
Android Question

Android: Remove background drawable programmatically

I want to remove background drawable (@drawable/bg) programmatically, is there a way to do that?

Currently I have the following XML code 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">



Answer

Try this

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

Check the setBackground functions in the RelativeLayout documentation