Reputation: 3090
So I have the coordinate layout as the root layout as I am using a floating Action button. Here is my xml.
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context=".activities.teacher.TeacherJobBoard"
android:id="@+id/rootLayout_job_board"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/anchor"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/color_black_darker_overlay"
android:layout_gravity="bottom"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/all_night_background"
android:orientation="vertical"
tools:context=".activities.teacher.TeacherJobBoard">
<com.hugocastelani.waterfalltoolbar.WaterfallToolbar
android:id="@+id/teacher_job_board_waterfall_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:final_elevation="15dp">
<androidx.appcompat.widget.Toolbar
android:id="@+id/teacher_job_board_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/tutor_bear_dark_blue"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme" />
</com.hugocastelani.waterfalltoolbar.WaterfallToolbar>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/discretescrollview_teacherJobBoard"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
</LinearLayout>
<com.github.ybq.android.spinkit.SpinKitView
android:id="@+id/spin_kit_job_board"
style="@style/SpinKitView.Large.WanderingCubes"
android:layout_width="@dimen/_80sdp"
android:layout_height="@dimen/_80sdp"
android:layout_gravity="center_horizontal|center_vertical"
app:SpinKit_Color="@color/color_white" />
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/extended_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:gravity="center"
style="@style/Widget.MaterialComponents.ExtendedFloatingActionButton.Icon"
android:onClick="expand"
app:iconSize="@dimen/_12sdp"
android:elevation="@dimen/_5sdp"
android:fontFamily="@font/roboto_light"
android:textColor="@color/white"
android:text="Filter"
app:iconPadding="@dimen/_5sdp"
android:layout_marginBottom="@dimen/_10sdp"
android:layout_marginRight="@dimen/_10sdp"
app:backgroundTint="@color/tutor_bear_dark_blue"
app:iconTint="@color/white"
app:icon="@drawable/ic_filter"
/>
<View
android:id="@+id/overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_black_darker_overlay"
android:visibility="gone"
/>
<include layout="@layout/bottom_filter_dialog"
android:id="@+id/filterSheet"
android:visibility="gone"
/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
I have a simple snack bar in my code like this.
Snackbar.make(binding.getRoot(), "This is main activity", Snackbar.LENGTH_LONG)
.setAction("CLOSE", new View.OnClickListener() {
@Override
public void onClick(View view) {
}
}). show();
Problem is when I show the snack bar , it always appears above a certain height from the bottom of the screen. As if there is some kind of a bottom margin set. This only happens when I use coordinate layout. Snackbar works fine in other layouts. Picture of the problem is given as a reference.
Upvotes: 2
Views: 726
Reputation: 10254
Give the root view instead, rootLayout_job_board
CoordinatorLayout rootLayout = findViewById(R.id.rootLayout_job_board);
Snackbar.make(rootLayout), "This is main activity", Snackbar.LENGTH_LONG)
.setAction("CLOSE", new View.OnClickListener() {
@Override
public void onClick(View view) {
}
}). show();
If that doesn't work, try giving GRAVITY
using LayoutParams
If that doesn't work, also give margins as 0 in LayoutParams. Also, if your device is Above 9 then you should consider navigation gestures,
snackbar.isGestureInsetBottomIgnored(false);
See here
Upvotes: 2