如图:
布局的xml文件中:
<ImageButton
android:id="@+id/fabButton"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_gravity="bottom|right"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
android:background="@drawable/fab_background" //圆形背景
android:src="@drawable/ic_favorite_outline_white_24dp" //圆形上的图片,自己设置
/>
drawable文件夹下的fab_background.xml:
<?xml version="1.0" encoding="utf-8"?>
<!--drawable/btn_fab_default.xml-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
//设置边框
<item android:bottom="0dp" android:left="2dp" android:right="2dp" android:top="2dp">
<shape android:shape="oval">
<solid android:color="@color/color_shadow" />
</shape>
</item>
//设置边框
<item android:bottom="2dp" android:left="2dp" android:right="2dp" android:top="2dp">
<shape android:shape="oval">
<solid android:color="@color/color_primary_red" />
</shape>
</item>
</layer-list>
values中的color.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="color_primary_red">#f44336</color>
<color name="color_primary_red_dark">#d32f2f</color>
<color name="color_primary_green"> #4caf50</color>
<color name="color_primary_green_dark">#388e3c</color>
<color name="color_shadow">#44000000</color>
</resources>