【问题标题】:floating action button ripple doesn't work浮动操作按钮波纹不起作用
【发布时间】:2020-02-19 19:00:49
【问题描述】:
我无法在浮动操作按钮上实现涟漪效果
我完全按照网上所说的进行了操作,但我看不到连锁反应
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/new_chat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:clickable="true"
android:src="@drawable/add_chat"
android:tooltipText="Start a new chat"
app:fabSize="normal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:maxImageSize="56dp"
app:rippleColor="@color/pastel_red" />
【问题讨论】:
标签:
android
xml
floating-action-button
【解决方案1】:
将此添加到您的styles.xml
<style name="SelectableItemTheme">
<item name="colorControlHighlight">@color/pastel_red</item>
</style>
<style name="SelectableItemBackground">
<item name="android:theme">@style/SelectableItemTheme</item>
<item name="android:background">?attr/selectableItemBackgroundBorderless</item> #this makes it round, if you want square, remove the word "Borderless"
</style>
然后
<com.google.android.material.floatingactionbutton.FloatingActionButton
style="@style/SelectableItemBackground"
android:id="@+id/new_chat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:clickable="true"
android:src="@drawable/add_chat"
android:tooltipText="Start a new chat"
app:fabSize="normal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:maxImageSize="56dp" />