There are two activations inherited from AppCompatActivity , in the markup of both classes there is a CoordinatorLayout and an embedded FloatingActionButton , while the behavior of the FAB when the keyboard appears is radically different. In MainActivity FAB pops up along with the keyboard, and in the second activity, when the keyboard appears, there is no. Below are the markup, the classes are almost identical.

activity_main.xml

 <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:id="@+id/main_coordinator_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" tools:context="ru.appchief.application.cargocalculator.MainActivity"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" 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" app:srcCompat="@drawable/ic_add_white_48dp" /> </android.support.design.widget.CoordinatorLayout> 

And almost identical second markup

activity_checkpoint.xml

 <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:id="@+id/checkpoint_coordinator_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <include layout="@layout/content_check_point" /> <android.support.design.widget.FloatingActionButton android:id="@+id/fab_add_checkpoint" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin" app:layout_behavior="@string/appbar_scrolling_view_behavior" app:srcCompat="@drawable/ic_add_location_white_48dp" /> </android.support.design.widget.CoordinatorLayout> 

At the moment, I'm wondering why in the second activation the CoordinatorLayout does not coordinate the behavior of the child object, as in the first activation?

    2 answers 2

    CoordinatorLayout never reacts to the keyboard. Here it is deeper.

    In order for the Activity to adapt to changing the position of the keyboard, you need to specify in the manifest for your activation the attribute: android:windowSoftInputMode="adjustResize" .

    https://stackoverflow.com/questions/17410499/difference-between-adjustresize-and-adjustpan-in-android

    • Thank you, partly the issue is resolved. But the behavior is different anyway. In the first case, FAB appears above the keyboard without the specified line in the manifest, but when SnackBar appears and disappears, it still falls behind the keyboard, in the second, the screen size changes with the line you specified (decreases the size of the keyboard) and accordingly FAB does not fail after the SnackBar disappears. Of course, you can write a line in the manifesto, but I want to understand the reason for the excellent behavior. - Michael

    The whole problem lies in the line

     app:layout_behavior="@string/appbar_scrolling_view_behavior" 

    in the activity_checkpoint.xml file. This is due to the fact that FAB "by default" has its own behavior ( FloatingActionButton.Behavior ). And since this line assigns the value of a Behavior type variable inside the FAB instance, the standard behavior becomes inaccessible. If you only need appbar_scrolling_view_behavior to fix FAB at the AppBarLayout level then use

     app:layout_anchor="@+id/id_вьюхи_к_которой_хотите_прикрепиться" //гравитация относительно вьюхи, к которой прикрепились app:layout_anchorGravity="стандартные переменные типа Gravity" 
    • I apologize, I forgot to remove the line, the problem remained without it, but with the comments above, the problem can be partly solved. - Michael