2011-01-17 29 views

回答

104

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

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

這應該工作 - imageButton.setBackgroundColor(android.R.color.transparent);

27

做在你的XML

<ImageButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/imageButtonSettings" 
     android:layout_gravity="right|bottom" 
     android:src="@drawable/tabbar_settings_icon" 
     android:background="@android:color/transparent"/> 
3

簡單在您的圖像按鈕佈局中使用此功能

android:background="@null" 

使用

android:background="@android:color/transparent 

btn.setBackgroundColor(Color.TRANSPARENT); 

不給完全透明

4

嘗試這樣

ImageButton imagetrans=(ImageButton)findViewById(R.id.ImagevieID); 

imagetrans.setBackgroundColor(Color.TRANSPARENT); 

OR

包括這在水庫的.xml文件/佈局

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

不使用TRANSAPENT或NULL佈局因爲那時button(或通用視圖)將沒有更多的亮點在點擊! !

我有同樣的問題,最後我從Android API找到正確的屬性來解決問題。它可以適用於任何視圖

使用此按鈕中規格

android:background="?android:selectableItemBackground" 

這需要API 11

+1

這正是我所需要的。使用'null'或'transparent'可禁用按鈕反饋。 – aks

1

如果你想使用Android R

textView.setBackgroundColor(ContextCompat.getColor(getActivity(), android.R.color.transparent)); 

並且不要忘記將支持庫添加到Gradle文件

compile 'com.android.support:support-v4:23.3.0'