How to set transparent background for Image Button in code?


Question

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(???);

1
74
7/26/2013 8:55:11 AM

Accepted Answer

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

    ImageButton btn=(ImageButton)findViewById(R.id.ImageButton01);
    btn.setBackgroundColor(Color.TRANSPARENT);
136
11/22/2012 8:37:42 AM

Do it in your xml

<ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageButtonSettings"
        android:layout_gravity="right|bottom"
        android:src="@drawable/tabbar_settings_icon"
        android:background="@android:color/transparent"/>

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon