【发布时间】:2017-12-16 10:57:27
【问题描述】:
我以前读过的东西
- Add ripple effect to my button with button background color?
- Android ripple for button not working
- Ripples on a shape with a transparent background
- Transparent background in ImageButton with ripple effect?
- RippleDrawable - dev
我需要使自定义波纹效果仅覆盖图像的 Alpha 通道或避免覆盖透明点。
我原来的按钮
<Button
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_gravity="center"
android:background="@drawable/btn_round"
android:foreground="@drawable/btn_ripple"/>
我从按钮建议中尝试过的内容
android:background="?attr/selectableItemBackgroundBorderless"
android:foreground="?attr/selectableItemBackgroundBorderless"。它不太奏效。事实上,它忽略了我的图像边框和波纹中设置的形状,而我需要将波纹扩散形状限制为 Alpha 通道。
如您所见,我有 3 个选项可以组合
- 自定义按钮形状
- 自定义波纹
- 从建议的选项中截断 Alpha 通道
所以我尝试将button 转换为imageButton
<ImageButton
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_gravity="center"
android:background="@drawable/btn_round"
android:foreground="@drawable/btn_ripple"
android:scaleType="fitXY"/>
但是,我尝试了所有 3 个 src、background 和 foreground 的所有组合,但没有成功。也尝试添加
android:background="?attr/selectableItemBackgroundBorderless"
android:foreground="?attr/selectableItemBackgroundBorderless" 涟漪。这也不行。
参考这张图片(那张没有 alpha 但事实并非如此)
【问题讨论】:
标签: android android-layout button