У меня есть плавающая кнопка действия в xml ниже и работает без ошибок
фрагмент_он. xml
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/btnFloatMain"
android:layout_width="80dp"
android:layout_height="80dp"
android:clickable="true"
android:layout_gravity="bottom|right"
android:layout_marginBottom="15dp"
android:layout_marginRight="15dp"
app:maxImageSize="80dp"
app:fabCustomSize="80dp"
app:srcCompat="@drawable/button_float_main"
/>
Однако я хотел установить состояния кнопок плавающей кнопки при нажатии, поэтому я создал xml ниже
button_states_float_main. xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
app:maxImageSize="80dp"
app:fabCustomSize="80dp"
app:srcCompat="@drawable/button_float_main_pressed"/>
<item
app:maxImageSize="80dp"
app:fabCustomSize="80dp"
app:srcCompat="@drawable/button_float_main"/>
</selector>
и изменил свою кнопку xml to
frag_one. xml
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/btnFloatMain"
android:layout_width="80dp"
android:layout_height="80dp"
android:clickable="true"
android:layout_gravity="bottom|right"
android:layout_marginBottom="15dp"
android:layout_marginRight="15dp"
app:srcCompat="@drawable/button_states_float_main"
/>
, но я не думаю, что настрою его правильно, так как мое приложение сейчас падает.