1

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.

enter image description here

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:

enter image description here

Any suggestions are highly appreciated. Thanks.

Community
  • 1
  • 1
Darush
  • 11,403
  • 9
  • 62
  • 60

1 Answers1

2

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.

Community
  • 1
  • 1
mfaisalhyder
  • 2,250
  • 3
  • 28
  • 38
  • Ok, thanks for the reply. I will write my feedback as soon as I try your approach. – Darush Jan 07 '17 at 07:05
  • after adding ScrollingFABAnimation as my FAB layout_behavour I am getting a strange behavior. FAB goes up about half the size of the screen above the soft keyboard. – Darush Jan 07 '17 at 07:45
  • did you use same XML properties ? – mfaisalhyder Jan 07 '17 at 08:04
  • 1
    Same problem even after using your xml file. – Darush Jan 07 '17 at 08:51
  • FAB is located in the middle of the screen to the right. Something must be wrong with your code or some sort of compatibility issue with 6.0.1. – Darush Jan 07 '17 at 08:52
  • android:layout_alignParentBottom="true" are you sure about this ? also add, android:windowSoftInputMode="adjustResize" in activity in manifest.xml. – mfaisalhyder Jan 07 '17 at 10:26