包括浮动操作按钮库

Include Floating Action Button library

我是 Android Studio 的初学者,我使用以下库 https://github.com/futuresimple/android-floating-action-button 将浮动操作按钮添加到我的项目中,但我不知道该怎么做。请指导我。

只需将依赖项添加到您的 build.gradle:

dependencies {
    compile 'com.getbase:floatingactionbutton:1.9.0'
}

要查看如何将按钮添加到您的 xml 布局,请查看示例项目。

求知:

您可以通过两种方式使用库:

  1. 第一种方式,如果库所有者在 Maven Central 或任何其他存储库上发布了库,那么我们只需要在 build.gradle 文件中使用给定的工件 ID。示例:com.getbase:floatingactionbutton:1.9.0, com.android.support:appcompat-v7:21.0.3
  2. 另一种方法是在您的项目中引用库项目,与我们在 Eclipse 中所做的相同。

针对 AndroidX 更新:

您可以使用 Google 的 FAB 原生实现:com.google.android.material.floatingactionbutton.FloatingActionButton

依赖性:com.google.android.material:material:1.0.0


以前(AndroidX之前):

我建议使用 Google 提供的设计支持浮动操作按钮,而不是此处 http://android-developers.blogspot.com/2015/05/android-design-support-library.html 将此添加到您的 gradle:

dependencies {
    compile 'com.android.support:design:23.0.0'
}

这将包括此处显示的 FloatingActionButton:http://developer.android.com/reference/android/support/design/widget/FloatingActionButton.html?utm_campaign=io15&utm_source=dac&utm_medium=blog

通常使用受支持的库比使用第 3 方库更好。

我来晚了一点,但对于那些正在寻找如何将浮动操作按钮添加到需要 changes in project due to recent migrations to androidx 的项目的人来说,这里是答案。代替 com.android.support:design 使用新的 com.google.android.material:material:1.0.0-rc01:

dependencies {
    implementation 'com.google.android.material:material:1.0.0-rc01'
}

同步项目后,只需在 activity xml 文件中声明 FAB:

<com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="16dp"
        android:layout_marginEnd="24dp"/>