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

请帮助。


当前回答

将ImageButton的背景设置为XML中的@null

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

其他回答

尝试使用null作为背景…

android:background="@null"

将ImageButton的背景设置为XML中的@null

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

使用ImageView……它默认有透明的背景…

删除这一行:

android:background="@drawable/transparent">

在你的活动课集中

ImageButton btn = (ImageButton)findViewById(R.id.previous);
btn.setAlpha(100);

可以将alpha级别0设置为255

O表示透明,255表示不透明。

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

<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>