Android – How to make button transparent in the app yet visible

androidbuttontransparency

I want my buttons to be transparent as I have an image on the activity as a background.
If the buttons are not transparent, those buttons are covering the image and image background seems useless.

If I use android:background="@android:color/transparent", it is making my button completely invisible except the text on it. So, I need the button to be transparent provided it should be visible that there is a button. Code snippet would be appreciated.

<Button
android:id="@+id/new_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"  //this line makes the button completely invisible.
android:text="@string/label" />

Best Answer

If you just want white borders, and the text/icons in the button, but the button background transparent create the following drawable (I named it button_border.xml):

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape>
            <stroke
                android:color="@android:color/white"
                android:width="1dp" />
            <solid android:color="@android:color/transparent" />
        </shape>
    </item>
</selector>

And use it as a background for the button:

<Button
    .
    .
    .
    android:background="@drawable/button_border"
    />

I'd guess there is a more elegant way to do it with themes, but I'm not that far yet. In the button_border drawable you can add rounded corners and whatnot...