简体   繁体   中英

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?

在此处输入图片说明

<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>

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>

try this:

MybuttonName.getBackground().setAlpha(0);

0= Completely transparent. 255 Completely opaque.

How about this.

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

尝试这个

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM