我正在创建一个 Android 应用程序,我想使用扩展的浮动操作按钮,所以我将此代码添加到我的活动中:
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/new_game_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_gravity="bottom|center"
android:text="@string/main_new_game"
android:backgroundTint="@color/colorAccent"
app:icon="@drawable/ic_play_arrow_24px"/>
该按钮看起来与它应该的完全一样,除了它在点击时没有涟漪效应。
如何添加涟漪效果?我直接从https://material.io/develop/android/components/floating-action-button/#extended-fabs获取代码,看起来波纹应该默认存在,但它在我的应用程序中不起作用. 我试图创建一个新项目,我只设置了材料组件(https://material.io/develop/android/docs/getting-started/)并且按钮仍然没有涟漪效应。因此,我的项目设置似乎没有问题。
我也试过设置app:rippleColor
属性,设置android:clickable="true" android:focusable="true"
无济于事。唯一起作用的是设置android:foreground="?attr/selectableItemBackground"
,但波纹效果被掩盖为矩形,而不是扩展 FAB 的形状。设置前景也不是很好的方法,因为它仅在 API 23 及更高版本上受支持,而我的目标是 API 21。