Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Floating action button in andoidx library

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?

like image 240
Virendra Varma Avatar asked Oct 12 '18 12:10

Virendra Varma


People also ask

How do I add a floating action button?

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.

Where is the floating action button?

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.

What is a floating action button?

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.

How do I add a floating action button in Recyclerview?

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.


2 Answers

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 of FloatingActionButton

app:backgroundTint="@color/colorAccent" is used to change background color of FloatingActionButton

To use FloatingActionButton inside activity or fragment we need to import FloatingActionButton like this

import com.google.android.material.floatingactionbutton.FloatingActionButton
like image 130
AskNilesh Avatar answered Sep 24 '22 16:09

AskNilesh


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'
like image 41
CHARFEDDINE Amine Avatar answered Sep 23 '22 16:09

CHARFEDDINE Amine