jueves, 12 de diciembre de 2013

Android: Making a button with hover / no hover images

In this example I wanted to make a custom Twitter button for my login page.

Steps:

1 - Create a Selector resource file and place it in the res/drawables folder. Each item associates an image with a state. Android will make the drawable changes for you.
2 - Create an ImageView in the desired layout and set its "src" to the Selector resource file name. Here you can also set the image's background. It depends on what you want to achieve.

Example:

Step 1:

res/drawables/register_button_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/register_button_hover"
        android:state_pressed="true"
/>
    <item android:drawable="@drawable/register_button"
        android:state_enabled="true"
/>
</selector>


Step 2:

<ImageView
        ...

        android:clickable="true"
        android:src="@drawable/register_button_selector"
        ... />

No hay comentarios:

Publicar un comentario