在android5.0新增了ripple的效果,他可以运用到Button,ImageButton,TextView,以及一些布局容器。

首先,我们看android:Theme.Material.Light主题中设置的各种ripple效果属性的默认值:

1.@drawable/item_background_material

2.@drawable/item_background_borderless_material

3.@style/Widget.Material.Light.Button.Borderless

4.@style/Widget.Material.Light.Button.ButtonBar.AlertDialog

selectableItemBackground在drawable文件中文件内容为:

android:color="?attr/colorControlHighlight">

selectableItemBackgroundBorderless在drawable文件中文件内容为:

android:color="?attr/colorControlHighlight" />

borderlessButtonStyle最后引用的style就是如下:

@drawable/btn_borderless_material

@null

他实际上就是设置了background的属性:

android:color="?attr/colorControlHighlight">

android:drawable="@drawable/btn_default_mtrl_shape" />

buttonBarButtonStyle实际上也是调用了borderlessButtonStyle的style,就是也是调用了相同的backgroung:

@drawable/btn_borderless_material

@null

?attr/colorAccent

@anim/disabled_anim_material

前两种在xml中设置background即可,如:

android:background="?android:selectableItemBackground"

前两种在xml中设置style即可,如:

style="?android:buttonBarButtonStyle"

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐