Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include Floating Action Button library

I am a beginner at Android Studio and using the following library https://github.com/futuresimple/android-floating-action-button to add Floating Action Button into my project but I don't know how to do that. Please guide me.

like image 860
Adhish Avatar asked May 22 '15 10:05

Adhish


3 Answers

Updated for AndroidX:

You can use Google's native implementation of FAB: com.google.android.material.floatingactionbutton.FloatingActionButton

Dependency: com.google.android.material:material:1.0.0


Previously (before AndroidX):

I would suggest using the Design Support Floating Action Button supplied by Google instead as seen here http://android-developers.blogspot.com/2015/05/android-design-support-library.html add this to your gradle:

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

and that will include the FloatingActionButton shown here: http://developer.android.com/reference/android/support/design/widget/FloatingActionButton.html?utm_campaign=io15&utm_source=dac&utm_medium=blog

It is generally a better practice to use a supported library than a 3rd party one.

like image 51
Rumadon Avatar answered Oct 22 '22 21:10

Rumadon


I'm a little bit late, but for those who will be looking on how to add Floating Action Button to project that requires changes in project due to recent migrations to androidx here is the answer. Instead of com.android.support:design use new com.google.android.material:material:1.0.0-rc01:

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

After syncing project just declare FAB in your activity xml file:

<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"/>
like image 5
devaerial Avatar answered Oct 22 '22 20:10

devaerial


Just add the dependency to your build.gradle:

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

To see how the buttons are added to your xml layouts, check the sample project.

For knowledge:

There are two ways you can use library:

  1. First way, if the library owner has published library on maven central or any other repository, then we just need to use the given artifact ID in build.gradle file. Example: com.getbase:floatingactionbutton:1.9.0, com.android.support:appcompat-v7:21.0.3
  2. Another way is to refer the library project in your project, same as what we were doing in Eclipse.
like image 3
Paresh Mayani Avatar answered Oct 22 '22 20:10

Paresh Mayani