Floating action button in andoidx library
Now you can migrate to Android x and replace the xml with:
<com.google.android.material.floatingactionbutton.FloatingActionButton ... />
Also in the gradle file add:
implementation 'com.google.android.material:material:1.0.0'
To use Floating action button in andoidx library use below dependencies
implementation 'com.google.android.material:material:1.0.0-rc01'
For more information check Migrating to AndroidX
Complete example
XML code
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/imgFour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_close"
app:backgroundTint="@color/colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tint="@android:color/white" />
Notes
app:tint="@android:color/white"
is used to change the icon color ofFloatingActionButton
app:backgroundTint="@color/colorAccent"
is used to changebackground
color ofFloatingActionButton
To use
FloatingActionButton
inside activity or fragment we need to importFloatingActionButton
like this
import com.google.android.material.floatingactionbutton.FloatingActionButton