我的代码:
<ImageButton
android:id="@+id/button_backspace"
style="@style/ButtonStyle"
android:src="@drawable/ic_backspace"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/button_zero"
app:layout_constraintTop_toBottomOf="@+id/button_nine"
app:tint="@drawable/background_button_text_color" />
<style name="ButtonStyle">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">0dp</item>
<item name="android:textSize">32sp</item>
<item name="android:textColor">@drawable/background_button_text_color</item>
<item name="android:background">@drawable/background_button</item>
</style>
background_button.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@android:color/white" android:state_pressed="false" />
<item android:drawable="@android:color/black" android:state_pressed="true" />
</selector>