Adz
Adz

Reputation: 2847

Making a button transparent Android?

How do I get rid of the white bit around the button? I don't want the button transparent, but I want the white bit around it. I've got Google Maps behind the button.

I've tried android:background="@android:color/transparent", on the Button, but it's only the button that becomes transparent (not the white bit around it).

How do I do this in XML?

enter image description here

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MyLocation" >

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:background="@android:color/transparent"
        android:gravity="center" >

        <Button
            android:id="@+id/filter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="filterMenu"
            android:text="@string/filter_button" />
    </FrameLayout>

   <fragment 
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />

</LinearLayout>

Upvotes: 1

Views: 822

Answers (4)

Nitin
Nitin

Reputation: 149

try this

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

Upvotes: 0

Eilean Laborde
Eilean Laborde

Reputation: 37

try this:

MybuttonName.getBackground().setAlpha(0);

0= Completely transparent. 255 Completely opaque.

Upvotes: 1

Jeongbebs
Jeongbebs

Reputation: 4120

How about this.

Button filter = (Button) findViewById(R.id.filter);
filter.setBackgroundColor(Color.TRANSPARENT);

Upvotes: 0

flx
flx

Reputation: 14226

How about setting the background of RelativeLayout to transparent?

<RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent" >
        <Button
            android:id="@+id/filter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:onClick="filterMenu"
            android:text="@string/filter_button"
            />
        <fragment 
            android:id="@+id/map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            class="com.google.android.gms.maps.SupportMapFragment" />
    </RelativeLayout>

And why not using FrameLayout anyway? It's better in performance than RelativeLayout.

<FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:background="@android:color/transparent" >
        <Button
            android:id="@+id/filter"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="filterMenu"
            android:text="@string/filter_button"
            />
        <fragment 
            android:id="@+id/map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            class="com.google.android.gms.maps.SupportMapFragment" />
    </FrameLayout>

Upvotes: 1

Related Questions