I'm trying to make a Button change color by pressing it but there's no way
activity_xml:
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"