2011-01-17 30 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'