【发布时间】:2017-02-19 21:13:20
【问题描述】:
我希望当用户点击按钮时,它的背景会发生一点变化,以获得它被点击的效果。
我的活动 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" />
按钮形状 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>
我怎样才能达到这个效果?我试图实现我在类似的 stackoverflow 问题页面上找到的内容,但没有奏效。我是 Android 开发的新手,所以我可能不知道一些基础知识...
【问题讨论】:
标签: java android-studio button buttonclick