具有透明背景的图像和文本按钮

发布于 2024-12-18 13:20:05 字数 268 浏览 2 评论 0原文

我正在尝试让一个按钮看起来像我在下面发布的链接中的按钮。

它是一个透明按钮,图像位于顶部,文本位于底部。当单击发生时,整个边界框会突出显示。

这是按钮按下时的样子: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

[旋木] 2024-12-25 13:20:05

dor506的答案基本上是正确的,但我会使用 ImageButton 而不是 Button,并将其背景设置为透明(android:background="#00000000" - 0 alpha 是这里的关键位)在通过 android:src="@drawable/your_drawable_id" 应用您的 Drawable 之前。

如果这有帮助,这里是一个合适的可绘制对象的示例:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/button_hi" /> <!-- pressed -->
    <item android:drawable="@drawable/button_lo" /> <!-- default -->
</selector>

其中“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 via android:src="@drawable/your_drawable_id".

In case this helps, here is an example of a suitable Drawable:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@drawable/button_hi" /> <!-- pressed -->
    <item android:drawable="@drawable/button_lo" /> <!-- default -->
</selector>

where 'button_hi' / 'button_lo' are the two images you are switching as a result of a click.

后eg是否自 2024-12-25 13:20:05

我认为您无法通过按钮/图像按钮属性实现此结果。

这是一个简单的解决方案:
您可以创建两张图像,一张用于未单击时的按钮,一张用于按钮
当单击它时(后面是橙色......),

那么您应该创建一个选择器。它是一个处理点击/非点击/焦点图像行为的 xml。

最后给按钮选择器的背景

        <Button android:layout_width="wrap_content" android:background="@drawable/selector" 
        android:layout_height="wrap_content" />

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

        <Button android:layout_width="wrap_content" android:background="@drawable/selector" 
        android:layout_height="wrap_content" />
2024-12-25 13:20:05

从外观上看,您显示的图像似乎是一个 ImageButton ,该图像是一个 PNG 图像,整个图像都有透明部分。如果您想保持按钮处于选中状态,您应该能够修改 button 参数:

android:state_selected = "true"

尝试一下。

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 the button parameters:

android:state_selected = "true"

Try that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文