[英]change button background when clicked (xml)
I want that when the user clicks the button, the background of it will change a bit to get the effect that it has been clicked.我希望当用户点击按钮时,它的背景会改变一点以获得它被点击的效果。
The fragment of my activity XML file:我的活动 XML 文件的片段:
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnParse"
android:text="@string/get_games"
android:textColor="#FFF5F2"
android:textSize="20sp"
android:layout_marginBottom="93dp"
android:layout_alignParentBottom="true"
android:background="@drawable/buttonshape"
android:textStyle="italic"
android:textAlignment="center"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
Button shape XML:按钮形状 XML:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"
android:layout_width="match_parent"
android:layout_height="match_parent">
<corners
android:radius="100dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<gradient
android:angle="45"
android:centerX="0"
android:centerColor="#A80C16"
android:startColor="#E8E8E8"
android:endColor="#FF0F0F"
android:type="linear"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<padding
android:left="42dp"
android:top="0dp"
android:right="50dp"
android:bottom="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<size
android:width="270dp"
android:height="60dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<stroke
android:width="3dp"
android:color="#878787"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</shape>
How can I achieve this effect?我怎样才能达到这种效果? I tried to implement what I found on similar stackoverflow questions pages but it didn't work.
我试图实现我在类似的 stackoverflow 问题页面上发现的内容,但没有奏效。 I'm pretty new in Android development so I may don't know some basics...
我是 Android 开发的新手,所以我可能不知道一些基础知识......
Hy you can refere to this link http://www.viralandroid.com/2015/09/how-to-change-android-button-on-click-press-color.html and this one how to change background image of button when clicked/focused?你可以参考这个链接http://www.viralandroid.com/2015/09/how-to-change-android-button-on-click-press-color.html和这个如何改变按钮的背景图像当点击/聚焦时? Hope this will help you..Thanks
希望这会帮助你..谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.