具有透明背景的图像和文本按钮
我正在尝试让一个按钮看起来像我在下面发布的链接中的按钮。
它是一个透明按钮,图像位于顶部,文本位于底部。当单击发生时,整个边界框会突出显示。
这是按钮按下时的样子: http://i44.tinypic.com/24nle9e.png
不确定这个效果是用 Button 还是 ImageButton 实现的。有什么想法吗?谢谢。
I'm trying to get a button to look like the one at the link I've posted below.
It's a transparent button with image at the top and text on the bottom. When a click occurs, the whole bounding box gets highlighted.
This is how the button looks like when pressed: http://i44.tinypic.com/24nle9e.png
Not sure if this effect is achieved with a Button or an ImageButton. Any ideas? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
dor506的答案基本上是正确的,但我会使用 ImageButton 而不是 Button,并将其背景设置为透明(
android:background="#00000000"
- 0 alpha 是这里的关键位)在通过android:src="@drawable/your_drawable_id"
应用您的 Drawable 之前。如果这有帮助,这里是一个合适的可绘制对象的示例:
其中“button_hi”/“button_lo”是您通过单击切换的两个图像。
dor506's answer is basically correct, but I'd use a ImageButton instead of a Button, and set it's background to transparent (
android:background="#00000000"
- the 0 alpha is the key bit here) before applying your Drawable viaandroid:src="@drawable/your_drawable_id"
.In case this helps, here is an example of a suitable Drawable:
where 'button_hi' / 'button_lo' are the two images you are switching as a result of a click.
我认为您无法通过按钮/图像按钮属性实现此结果。
这是一个简单的解决方案:
您可以创建两张图像,一张用于未单击时的按钮,一张用于按钮
当单击它时(后面是橙色......),
那么您应该创建一个选择器。它是一个处理点击/非点击/焦点图像行为的 xml。
最后给按钮选择器的背景
I don't think you can achieve this result with button/imagebutton properties.
here's a simple solution:
you can create two images, one for the button when it isn't clicked, and one for the button
when it is clicked (with the orange color behind..)
then you should create a selector. it is an xml which handle click/non click/focus image behaviour.
finally give the button the background of the selector
从外观上看,您显示的图像似乎是一个
ImageButton
,该图像是一个 PNG 图像,整个图像都有透明部分。如果您想保持按钮处于选中状态,您应该能够修改button
参数:尝试一下。
By the looks of it, it appears the image you're showing is an
ImageButton
with the image being a PNG image with transparent sections throughout it. If you want to keep the button selected you should be able to mess with thebutton
parameters:Try that.