0

I would like to adding some effects like color change to my android button when user focus/click the button

My android button layout is here :

<Button
    android:id="@+id/btnUpload"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:background="@color/btn_bg"

    android:text="தகவல் அனுப்புக"
    android:textColor="@color/white"
    android:padding="20dp"
    android:margin="20dp"
    android:layout_alignParentBottom="true" />
nifCody
  • 2,394
  • 3
  • 34
  • 54
  • 1
    use a selector as the background. In your selector define the different states you need and use the colors, or images you want for them – peshkira Mar 10 '15 at 19:47

1 Answers1

1

You should check out the documentation regarding color state lists. Create an XML file in your drawable folder with the name of btn_background and place the following code in the file:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true"
          android:color="#ffff0000"/> <!-- pressed -->
    <item android:state_focused="true"
          android:color="#ff0000ff"/> <!-- focused -->
    <item android:color="#ff000000"/> <!-- default -->
</selector>

After you have created this file, change the background attribute of your Button to point to the new background:

android:background="@color/btn_background"

Good luck and happy coding!

John P.
  • 4,358
  • 4
  • 35
  • 47