Reputation: 12021
Normally when Snackbar is shown, Floating Action Button shifts up and then shifts down to its normal position when Snackbar hides. I have tested my application in all android versions before 6.0.1 and everything works as expected.
Unfortunately on android 6.0.1, after the Snackbar goes away the Floating Action Button goes half under the soft keyboard.
As per the Android guidelines I have CoordinatorLayout
as the parent layout. And I have also tried: android:windowSoftInputMode="adjustResize"
in the Manifest file.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:id="@+id/myCoordinatorLayout"
tools:context="com.example.myapp.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@mipmap/ic_add_white_24dp" />
</android.support.design.widget.CoordinatorLayout>
Is this some sort of bug? or is there any way to handle this programatically?
UPDATE: I have discovered that when I swipe to dismiss the Snackbar manually, the FAB comes back to its normal position. But if I let the snackbar until it hides/dismisses by itself, it will create the problem.
Using this approach suggested by @Muhammad Faisal Hyder
: Make FAB respond to Soft Keyboard show/hide changes I am getting the following result:
Any suggestions are highly appreciated. Thanks.
Upvotes: 1
Views: 1026
Reputation: 2284
I have given answer to this question asked by another person, you can try this post, yes there is a programming way to handle it, we need to extend CoordinatorLayout.Behavior<FloatingActionButton>
and override methods to achieve appropriate behaviours of FAB on scrolling (to hide and show) and on snack bar or keyboard pops up so Fab also moves accordingly.
After EDIT :
Above referenced answer works for me, well you can try these as well.
add : android:fitsSystemWindows="true"
in <android.support.design.widget.CoordinatorLayout/>
If above doesn't work, still, then,
add : android:windowSoftInputMode="adjustResize"
to your activity in Manifest.xml
Hope it will help you out.
Upvotes: 2