Already asked here but without a proper answer.
I want the FAB to float on top of the keyboard. that's it.
For example
Blank Activity
template project with Android StudioTextView
to EditText
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.
The button should be placed in the bottom right corner of the screen. The recommended margin for the bottom is 16dp for phones and 24dp for tablets. In the example above, 16dp was used. The actual drawable size should be 24dp according to the Google design specs.
Turns out it's pretty easy,
android:windowSoftInputMode="adjustResize"
to your activity in manifestandroid:fitsSystemWindows="true"
propertyIf you want to see FloatingActionBar move above keyboard, you should:
1) Insert FloatingActionBar inside CoordinatorLayout:
<androidx.coordinatorlayout.widget.CoordinatorLayout android:id="@+id/coordinator" android:layout_width="match_parent" android:layout_height="match_parent"> <com.google.android.material.floatingactionbutton.FloatingActionButton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_margin="16dp" android:src="@drawable/ic_img" /> </androidx.coordinatorlayout.widget.CoordinatorLayout>
2) Add in root View (where your FAB exist) code:
android:fitsSystemWindows="true".
For example:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" android:orientation="vertical" tools:context=".AddFilm"> <androidx.coordinatorlayout.widget.CoordinatorLayout android:id="@+id/coordinator" android:layout_width="match_parent" android:layout_height="match_parent"> <com.google.android.material.floatingactionbutton.FloatingActionButton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_margin="16dp" android:src="@drawable/ic_img" /> </androidx.coordinatorlayout.widget.CoordinatorLayout> </LinearLayout>
3) Add next code in AndroidManifest.xml to your Activity:
android:windowSoftInputMode="adjustResize"
For example:
<activity android:name=".MainActivity" android:windowSoftInputMode="adjustResize"/>
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