gpt4 book ai didi

android - Material Design Extended Floating Action Button 没有涟漪效应

转载 作者:行者123 更新时间:2023-12-04 09:40:44 25 4
gpt4 key购买 nike

我正在创建一个 Android 应用程序,我想使用扩展的 float 操作按钮,所以我将此代码添加到我的 Activity 中:

<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 获取了代码看起来涟漪默认应该在那里,但它在我的应用程序中不起作用。我试图创建新项目,我只设置了 Material 组件( 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。

最佳答案

您应该使用此属性 app:rippleColor

<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"
app:rippleColor="@color/colorPrimary" />

关于android - Material Design Extended Floating Action Button 没有涟漪效应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62346222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com