RSS

Android animating buttons

06 Jul

Create an xml file in the drawable folder and select the root element as “selector”.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item 
        android:state_pressed="true"
        android:drawable="@drawable/toast"
        >
    </item>
     <item 
        android:state_focused="true"
        android:drawable="@drawable/smart"
        >
    </item>
    
      <item 
        android:drawable="@drawable/looking"
        >
    </item>

</selector>

In the layout xml file let the background of the button refer to the above xml:

<Button
        android:id="@+id/badd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/custom" />

And now you have something that looks like:

When highlighted(focused):

And when you click on it:

Advertisements
 
 

Tags: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: