简单实现安卓圆形按钮及(圆形)波纹效果

效果图:
这里写图片描述
实现步骤:
1、在style.xml中添加

<style name="RippleWhite">
    <item name="android:colorControlHighlight">#FAFAFA</item>
    <item name="android:radius">25dp</item>
</style>
  • android:colorControlHighlight为点击后波纹的颜色
  • android:radius为效果半径(实测)

2、一个ImageButon

<ImageButton
   android:id="@+id/view_back"
   android:layout_width="50dp"
   android:layout_height="50dp"
   android:layout_gravity="center_vertical"
   android:layout_marginLeft="20dp"
   android:background="?android:attr/selectableItemBackgroundBorderless"
   android:contentDescription="@string/text_back"
   android:src="@drawable/ic_arrow_back_white_24dp"
   android:theme="@style/RippleWhite" />

其中重要属性android:background要设置为无边界的波纹

android:background="?android:attr/selectableItemBackgroundBorderless"

设置风格属性android:theme="@style/RippleWhite"

猜你喜欢

转载自blog.csdn.net/qq_37299249/article/details/78536772