How to assign click effects to an Imagebutton?

Asked

Viewed 1,570 times

0

For example, I added to my xml layout an Imagebutton, put an image and left with transparent background, for having done that it lost the characteristics of a button, how do I add click effect?

  • Try to reformulate this question by beginning and end and not simply "order", be specific, cordial and technical.

  • got better? @user3163662

  • I still can’t understand what you’re trying to do.

1 answer

3


You need to create a drawable for it, stating the colors for the respective states. To do this, create an . xml file inside the folder drawable:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true">
        <shape>
            <solid android:color="@color/sua_cor_selecionado" />
            <padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
        </shape>
    </item>
    <item android:state_focused="true">
        <shape>
            <solid android:color="@android:color/transparent" />
            <padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
        </shape>
    </item>
    <item android:state_enabled="false">
        <shape>
            <solid android:color="@android:color/transparent" />
            <padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
        </shape>
    </item>
    <item>
        <shape>
            <solid android:color="@android:color/transparent" />
            <padding android:bottom="3dp" android:left="3dp" android:right="3dp" android:top="3dp" />
        </shape>
    </item>

</selector>

And, after creating, assign in your ImageButton:

<ImageButton
    android:id="@+id/seu_botao"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/seu_arquivo_criado"/>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.