android - 具有类似 MaterialButton 的半透明波纹的 Android 自定义按钮
问题描述
我基于 MaterialButton 创建了自定义按钮,该按钮在按下和禁用时是半透明的(primaryColorDisabled)。现在,我想要让它的涟漪效应将按钮从它的primaryColor 变成primaryColorDisabled,而不是MaterialButton 的默认突出显示颜色。
我的颜色仅在 alpha 上有所不同,并且已定义:
<color name="primaryColor">#283593</color>
<color name="primaryColorDisabled">#A0283593</color>
对于我的自定义按钮,我应用以下样式:
<style name="CustomButton" parent="Widget.MaterialComponents.Button">
<item name="android:background">@drawable/custom_background</item>
</style>
以下是我的可绘制对象的递归定义。我删除了不相关的部分,如命名空间、填充、边距等。
@drawable/custom_background:
<selector>
<item android:state_enabled="false"
android:drawable="@drawable/custom_disabled" />
<item android:state_pressed="true"
android:drawable="@drawable/custom_disabled" />
<item android:drawable="@drawable/custom_ripple" />
</selector>
@drawable/custom_disabled:
<inset>
<shape
android:shape="rectangle"
android:tint="@color/primaryColorDisabled" >
<solid android:color="@color/primaryColor" />
</shape>
</inset>
@drawable/custom_ripple:
<ripple android:color="?attr/colorControlHighlight">
<item android:drawable="@drawable/custom_enabled" />
</ripple>
@drawable/custom_enabled:
<inset>
<shape
android:shape="rectangle" >
<solid android:color="@color/primaryColor" />
</shape>
</inset>
现在,我尝试在@drawable/custom_ripple中将颜色从?attr/colorControlHighlight 更改为我的@color/ primaryColorDisabled ,但是当我点击我的按钮时,没有任何变化:没有波纹,甚至没有“state_pressed”外观。任何想法如何实现这一目标?
解决方案
推荐阅读
- android - 'gradlew' 不是内部或外部命令、可运行程序或批处理文件
- python - 在列表或数组中搜索与子列表的最佳匹配(通过数值差异)?
- javascript - 如何删除 Fusion 图表(DonutChart)中图表和图例之间的填充?
- algorithm - 当线向下时检查点是否是线的一部分的算法不能正常工作
- elixir - Elixir 编译器对忽略函数返回值的警告
- node.js - 使用 Typescript mongoose 填充的 expressjs
- asp.net-mvc - iframe 偶尔会丢失会话 cookie
- linux - 为什么将“< /dev/null”与“bzip2”之类的程序一起使用?
- ksh - 是否有可以在 shell 脚本中运行的 m4a 字段编辑器?
- django - 如何即兴在终端上接收 django 后端电子邮件?