如何使用图像作为按钮如何使用、按钮、图像

2023-09-05 06:35:05 作者:我才不取辣么长的名字呢

这应该是轻松的一年,我真的以为我在做什么是正确的,但显然事实并非如此。我有,我想作为一个按钮使用图像,我有按钮创建工作。但现在我只想此图片显示的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"