如何使用图像作为按钮 [英] how to use an image as a button

查看:77
本文介绍了如何使用图像作为按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该是轻松的一年,我真的以为我在做什么是正确的,但显然事实并非如此。我有,我想作为一个按钮使用图像,我有按钮创建工作。但现在我只想此图片显示的standatd机器人按钮起来吧。

this should be an easy one and I really thought that what I was doing was correct but apparently it isn't. I have an image that I want to use as a button, I have the button created and working. But now I just want this image to show up instead of the standatd android "button".

任何人都知道如何做到这一点?

Anyone know how to do this?

推荐答案

请一个使用<选择

创建在所谓绘制,华电国际文件夹中的XML文件 button_image.xml

Create in your drawable-hdpi folder xml file called button_image.xml

和加上下面几行:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_focused="true" android:state_pressed="false" android:drawable="@drawable/picture" /> 
    <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/picture_pressed" /> 
    <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/picture_pressed" /> 
    <item android:drawable="@drawable/picture" /> 
</selector>

,然后在你的主XML,你申报你的按钮添加这行

and then in your main xml where you declare your button add this line

android:background="@drawable/button_image"

然后你会得到雷尔按钮的作用。需要注意的是,你需要两张照片来获得被点击按钮的作用。

And then you get effect of reall button. Note that you need two pictures to get effect of button being clicked.

如果你不想使用选择和只使用图片代替然后就

If you dont want to use the selector and use just picture instead then just

安卓背景=@可绘制/ MYIMAGE

android:background="@drawable/myimage"

这篇关于如何使用图像作为按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆