Change the color of a button when pressed [duplicated]

0

I'm trying to make a Button change color by pressing it but there's no way activity_xml:

drawable:

    
asked by Mihai Minca 01.02.2018 в 05:24
source

1 answer

2

The property checked can only be used to checkbox or radiobuttons the way you could use is the state_ to use the button to change color according to the state.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@color/red"/> <!-- presionado -->
    <item android:state_focused="true" android:drawable="@color/blue"/> <!-- en foco -->
    <item android:drawable="@color/black"/> <!-- por defecto -->
</selector>

Use the selector as background :

android:background="@drawable/butonpulsado"
    
answered by 01.02.2018 в 05:38