Include Floating Action Button library
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"/>
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:
- 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 - Another way is to refer the library project in your project, same as what we were doing in Eclipse.
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.