<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会在项目中给我一个错误。

请帮助。


当前回答

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

android:backgroundTintMode="screen"

其他回答

尝试使用null作为背景…

android:background="@null"

在编程上,它可以通过:

image_button.setAlpha(0f) // to make it full transparent
image_button.setAlpha(0.5f) // to make it half transparent
image_button.setAlpha(0.6f) // to make it (40%) transparent
image_button.setAlpha(1f) // to make it opaque

不要忘记添加填充,它有助于显示按钮效果。添加填充来调整背景。

android:background="?android:selectableItemBackground"
android:padding="5dp"

我认为公认的答案应该是: android:背景= " ?attr / selectableItemBackground”

这与@lory105的答案相同,但它使用了最大兼容性的支持库(android:等效只适用于API >= 11)

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

android:background="@null"

这是一个编程的例子

yourButton.setBackgroundResource(0);