android - 浮动操作按钮波纹不起作用
问题描述
我无法在浮动操作按钮上实现涟漪效果,我完全按照网上所说的内容进行操作,但我看不到涟漪效果
<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" />
解决方案
将此添加到您的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" />
推荐阅读
- spring-boot - What is the proper dependency configuration for Vaadin CssLayout
- excel - 使用 Excel 创建 Visio ER 图
- mysql - 将数据库数据从 express.js 服务器传递到 react.js 组件
- c# - Using WPF/MVVM, how do I pass the SelectedIndex value of a Listbox to my ViewModel?
- jdbc - 错误转换:weblogic.jdbc.wrapper.JTAConnection...jdbc_driver_LogicalConnection 转换为 oracle.jdbc.OracleConnection
- java - 如何修复“ClassNotFoundException:brave.propagation.CurrentTraceContext$ScopeDecorator”?
- r - 在 ggplot2 中绘制数据的频率
- html - stroke-dasharray 和 stroke-dashoffset 在 IE11 中不起作用
- javascript - 将 cookie 值设置为 json 对象值
- javascript - 如何在不刷新浏览器的情况下在代码之外的 Javascript 中停止 setInterval 循环?