制作透明Android按钮?

时间:2013-12-05 02:56:12

标签: android button

如何摆脱按钮周围的白色位?我不希望按钮透明,但我想要它周围的白色位。我在按钮后面有谷歌地图。

我在按钮上尝试了android:background =“@ android:color / transparent”,但它只是变为透明的按钮(不是它周围的白色位)。

如何在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>

4 个答案:

答案 0 :(得分:1)

如何将RelativeLayout的背景设置为透明?

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

为什么不使用FrameLayout呢?它的性能优于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>

答案 1 :(得分:1)

试试这个:

MybuttonName.getBackground()setAlpha(0);

0 =完全透明。 255完全不透明。

答案 2 :(得分:0)

这个怎么样。

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

答案 3 :(得分:0)

试试这个

android:background="@android:color/transparent"
相关问题