Hi is there anyone knows how to use the floating action button with andoidx library I think in android x library they replace
implementation 'com.android.support:appcompat-v7:xx.xx.xx'
by
implementation 'androidx.appcompat:appcompat:1.0.0'
but it's not helping any suggetion?
Add the floating action button to your layoutThe size of the FAB, using the app:fabSize attribute or the setSize() method. The ripple color of the FAB, using the app:rippleColor attribute or the setRippleColor() method. The FAB icon, using the android:src attribute or the setImageDrawable() method.
A floating action button (FAB) performs the primary, or most common, action on a screen. It appears in front of all screen content, typically as a circular shape with an icon in its center.
Floating Action Button (FAB) is a very common UI control for Android apps. Shaped like a circled icon floating above the UI, it's a tool that allows users to call out the key parts of your app. FAB is quite simple and easy to implement UI element, despite that designers often incorrectly incorporate it into layouts.
you need to use Relative layout instead Linear. Look at my code for floatingActionButton, this will help you. In my case, putting it under a Relative layout led me to an error similar to this >> stackoverflow.com/questions/46030137/…. My list isn't being populated anymore.
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
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" />
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
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With