如何解决设置ImageButton的不透明度?
| 我想为我的ImageButton设置不透明度,所以当未选择它时,我可以看到一些背景,当我按下它时,它会变成正常(不透明)。解决方法
如果您使用的背景本身就是图像,则不能简单地“设置”透明度,它来自作为背景资源的png图像。我建议您根据需要为任意阶段使用透明度为按钮的不同阶段创建3张9补丁png图像。在ImageButton的文档中有关于如何为自己的背景图像使用不同的图形和xml配置文件的描述
http://developer.android.com/reference/android/widget/ImageButton.html
如果您使用纯色作为背景,则可以使用以AARRGGBB作为元素的颜色代码来实现透明度。
android:background = \“#55FF0000 \”将是部分透明的红色背景。
,使用选择器(http://developer.android.com/reference/android/content/res/ColorStateList.html)
布局代码看起来像这样:
android:background=\"@drawable/my_selector\"
选择器代码为my_selector.xml,内容如下:
<selector xmlns:android=\"http://schemas.android.com/apk/res/android\" >
<item android:state_pressed=\"true\" android:drawable=\"@drawable/button_without_opactity\" />
<item android:state_selected=\"true\" android:drawable=\"@drawable/button_without_opactity\" />
<item android:drawable=\"@drawable/button_with_opacity\" />
</selector>
button_without_opacity和button_with_opacity应该为9个补丁
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。