2014-01-29 92 views
3

我有像這樣的按鈕...是否可以使按鈕的背景透明?

enter image description here

很抱歉,如果它看起來暗,但你可以看到,我已經設置了高度和寬度來包裝內容,但scaletype不fitxy所以如果你願意,仍然是「按鈕過剩」。

有什麼方法可以刪除它嗎?

+0

使用'ImageButton'和它的背景設置爲透明這樣的:'機器人:背景=「@機器人:彩色/透明」' – Houcine

+0

實際上這是當你使用ImageButton作爲src時的圖像問題,你也會得到透明的圖像。 –

回答

3

使用ImageButton和一套什麼它的背景透明如下:android:background="@android:color/transparent"

<ImageButton 
     android:id="@+id/btn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@android:color/transparent" 
     android:src="@drawable/btn_login" /> 
3

//是的,你可以用XML做通android:alpha

//在按鈕屬性添加此線下方,並改變你的阿爾法水平,只要你想

android:alpha="0.5" 
4

你可以使用ImageButton。這樣做在你的XML

<ImageButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/imageButtonSettings" 
    android:src="@drawable/tabbar_icon" 
    android:background="@android:color/transparent"/> 

或編程。這是一個簡單的只有你需要設置背景顏色爲透明

ImageButton btn=(ImageButton)findViewById(R.id.ImageButton01); 
btn.setBackgroundColor(Color.TRANSPARENT); 
1

使用#0000(僅四個零,否則將被視爲黑)這是透明的顏色代碼。您可以直接使用它,但我建議您在color.xml中定義一種顏色,以便您可以重新使用代碼。

+0

準確地說:在這些情況下,它將被視爲**黑色**:#000,#f000,#000000和#ff000000 –

0

添加以下的屬性到按鈕標籤

<button 
android:background="@android:color/transparent"/> 
+0

爲什麼投票下降? –