-2

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:

<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 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. I'm pretty new in Android development so I may don't know some basics...

EtherPaul
  • 424
  • 10
  • 19

1 Answers1

-1

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? Hope this will help you..Thanks

Community
  • 1
  • 1
Sardar Khan
  • 845
  • 6
  • 16