<ImageButton android:id="@+id/previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/media_skip_backward"
android:background="@drawable/transparent"></ImageButton>

这是我试图获得一个透明的ImageButton,以便将这些按钮放在SurfaceView上。但是当我在xml中包含透明行时,Eclipse会在项目中给我一个错误。

请帮助。


当前回答

背景设置为“@null”将使按钮在点击时无效。这将是更好的选择。

style="?android:attr/borderlessButtonStyle"

后来我发现这很有用

android:background="?android:attr/selectableItemBackground"

也是一个很好的解决方案。你可以用你自己的风格继承这个属性。

其他回答

如果你需要一个点击动画,不要使用空或透明。好:

//Rectangular click animation
android:background="?attr/selectableItemBackground"

//Rounded click animation
android:background="?attr/selectableItemBackgroundBorderless"

最好的方法是使用透明的颜色代码

android:background="#00000000"

使用颜色代码#00000000使任何东西透明

用这个:

<ImageButton
 android:id="@+id/back"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:background="@null"
 android:padding="10dp"
 android:src="@drawable/backbtn" />

它工作,也保持按钮点击的视觉反馈,

android:backgroundTintMode="screen"

如果你想在.xml文件中使用下面的代码:

android:background="@null"

这是一个编程的例子

yourButton.setBackgroundResource(0);