<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作为背景…

android:background="@null"

其他回答

不要使用透明或空布局,因为这样按钮(或通用视图)在点击时将不再突出显示!!

我有同样的问题,最后我从Android API找到了正确的属性来解决这个问题。它可以应用于任何视图。

在按钮规范中使用这个:

android:background="?android:selectableItemBackground"

在运行时,可以使用以下代码

btn.setBackgroundDrawable(null);

你可以使用下面的代码通过设置背景为透明工作:

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

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

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

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

android:background="#00000000"

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