Following the tips given in this thread I'm setting the bottom margin of a snackbar to ca. 55 dp in order to have it above the FAB.
The code is - as in the other question:
Snackbar snackbar = Snackbar.make(constraintLayoutContent, msg, Snackbar.LENGTH_LONG);
snackbar.setAction(action, v -> snackbar.dismiss());
View snackBarView = snackbar.getView();
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) snackBarView.getLayoutParams();
params.setMargins(params.leftMargin,
params.topMargin,
params.rightMargin,
params.bottomMargin + 500);
//params.gravity = Gravity.TOP;
snackBarView.setLayoutParams(params);
snackbar.show();
The problem I'm facing is that if the snackbar is at the bottom of the screen (params.gravity = Gravity.BOTTOM;
) the bottom margin is not applied; however if the snackbar is placed at top of the screen (params.gravity = Gravity.TOP; params.topMargin = 500;
) the top margin is correctly applied.
Two screenshots of the issue:
Thanks for your help.
EDIT:
The following is my layout xml file. Not sure if this could help, but here we are.
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayoutContent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/constraintLayoutContent">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>