首页 > 解决方案 > 如何在按下时更改材质浮动操作按钮的颜色?

问题描述

按下按钮时如何更改 FAB 的颜色?我没有看到像onPressed().

标签: androidxmlkotlinmaterial-designfloating-action-button

解决方案


You can use the app:rippleColor in your layour or the rippleColor attribute in the FAB style.

Where fab_ripple should be a selector.

Something like:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
      <item android:alpha="..." android:color="?attr/colorOnSecondary" android:state_pressed="true"/>
      <item android:alpha="..." android:color="?attr/colorOnSecondary" android:state_focused="true"/>
      <item android:alpha="..." android:color="?attr/colorOnSecondary" android:state_hovered="true"/>
      <item android:alpha="..." android:color="?attr/colorOnSecondary"/>

</selector>

推荐阅读