How to set transparent background for Image Button in code?

Peter picture Peter · Jan 17, 2011 · Viewed 128.4k times · Source

I can set ImageButton background transparent in layout.xml using:

android:background="@android:color/transparent"

How I can acomplish same thing using java code? Something like ib.setBackgroundColor(???);

Answer

Parag Chauhan picture Parag Chauhan · Jan 17, 2011

This is the simple only you have to set background color as transparent

    ImageButton btn=(ImageButton)findViewById(R.id.ImageButton01);
    btn.setBackgroundColor(Color.TRANSPARENT);