【发布时间】:2012-03-01 01:03:39
【问题描述】:
我已经按照这篇文章在 android 中制作 ImageButton
图像出现在按钮上,但它有一些背景,我的图像是 png 图像,我希望按钮是透明背景
请大家帮忙
【问题讨论】:
标签: android imagebutton
我已经按照这篇文章在 android 中制作 ImageButton
图像出现在按钮上,但它有一些背景,我的图像是 png 图像,我希望按钮是透明背景
请大家帮忙
【问题讨论】:
标签: android imagebutton
将此行添加到您的 ImageButton xml 布局中。
android:background="@null"
【讨论】:
android:background="@null" android:src="@drawable/myimage"
这是一个对我有用的替代解决方案:
android:background="@android:color/transparent"
正如 Sunny 所说,将其添加到 ImageButtons 的 XML 布局中
【讨论】:
在你的代码中使用这个:
ImageButton btn = new ImageButton(this);
btn.setImageResource(R.drawable.btn_close);
btn.setBackgroundResource(0);
【讨论】:
我不知道是否有任何方法可以做到这一点,但是您可以绘制完全透明的 .png 文件并使用方法 setBackGroundResource() 或在 XML 中使用:android:background
【讨论】:
通过这种方式可以给ImageButton设置透明背景:
<ImageButton android:id="@+id/imagebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/<imageresourcename>"
android:background="@null"></ImageButton>
【讨论】: