2013-12-05 3 views
1

Как избавиться от белого бита вокруг кнопки? Я не хочу, чтобы кнопка была прозрачной, но я хочу, чтобы вокруг нее был белый бит. У меня есть Google Maps за кнопкой.Сделать кнопку прозрачной 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> 
+0

Это полный XML? Если не опубликовать все это. –

+0

Весь XML сейчас. – Adz

+0

это не правильный XML. – flx

ответ

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

Спасибо за ответ, кнопка все тот же. – Adz

0

Как насчет этого.

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

попробовать это:

MybuttonName.getBackground() SetAlpha (0);.

0 = Полностью прозрачный. 255 Полностью непрозрачный.

0

попробовать это

android:background="@android:color/transparent" 
Смежные вопросы