使用这个库我解决了我的问题。
https://github.com/shell-software/fab
第 1 步:您必须将此依赖项放入 build.gradle 文件中
dependencies {
compile 'com.github.shell-software:fab:1.1.2'
}
第 2 步:将其写入您的 xml 文件中。
<com.software.shell.fab.ActionButton
android:id="@+id/action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="@dimen/fab_margin"
android:layout_marginBottom="@dimen/fab_margin"
/>
步骤:3初始化ActionButton
ActionButton actionButton = (ActionButton) findViewById(R.id.action_button);
步骤:4针对不同的目的应用不同的效果。
1.移动动作按钮
int distance = 100.0f // in density-independent pixels
// Move ActionButton left
actionButton.moveLeft(distance);
2。按钮类型
您可以使用三种类型的操作按钮:
-
默认 (56dp)
-
迷你(40dp)
-
大(72dp)
3.按钮大小
要使用 ActionButton 大小,请使用:
// To get the ActionButton size
float size = actionButton.getSize();
// To set the ActionButton size
actionButton.setSize(60.0f); //
4.按钮状态
有两种按钮状态,Action Button 可能驻留在其中:
5.按钮颜色
按钮颜色可以设置为 NORMAL 状态,所以对于 PRESSED 状态。默认设置以下颜色:
#FF9B9B9B for the NORMAL state
#FF696969 for the PRESSED state
6.影子
可以通过三种方式自定义阴影:颜色、半径和偏移。默认情况下启用阴影并具有以下默认值:
- shadowColor = #42000000(~浅灰色)
- shadowRadius = 8.0f(与密度无关的像素)
- shadowXOffset = 0.0f(与密度无关的像素)
- shadowYOffset = 8.0f(与密度无关的像素)
7.图片
您可以使用以下代码更改 actionButton 图像。
actionButton.setImageBitmap(bitmap);
actionButton.setImageDrawable(getResource.getDrawable(R.drawable.fab_plus_icon));
actionButton.setImageResource(R.drawable.fab_plus_icon);
8.中风
可以通过两种方式自定义描边:宽度和颜色。默认情况下禁用描边,但它具有默认值:
- strokeColor = Color.BLACK
- strokeWidth = 0.0f(无描边)
短
在 XML 中你直接定义所有的东西
xml 是:
<com.software.shell.fab.ActionButton
android:id="@+id/action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/fab_margin"
android:layout_marginBottom="@dimen/fab_margin"
fab:type="DEFAULT"
fab:button_color="@color/fab_material_lime_500"
fab:button_colorPressed="@color/fab_material_lime_900"
fab:image="@drawable/fab_plus_icon"
fab:image_size="24dp"
fab:shadow_color="#757575"
fab:shadow_radius="1.0dp"
fab:shadow_xOffset="0.5dp"
fab:shadow_yOffset="1.0dp"
fab:stroke_color="@color/fab_material_blue_grey_500"
fab:stroke_width="1.0dp"
fab:button_colorRipple="@color/fab_material_black"
fab:rippleEffect_enabled="false"
fab:shadowResponsiveEffect_enabled="true"
fab:show_animation="@anim/fab_roll_from_down"
fab:hide_animation="@anim/fab_roll_to_down"
/>