Snackbar hidden by bottom navigation

1.3k Views Asked by At

My Snackbar is being hidden by the bottom navigation buttons.

Hidden Snackbar

The Activity is able to toggle full screen mode and I do not want to use margins offsets to fix this.

My XML layout is:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/image_background"
    tools:context="link.standen.michael.slideshow.ImageActivity">

    <ImageView
        android:id="@+id/fullscreen_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:keepScreenOn="true"
        android:contentDescription="@string/image_description"/>

    <!-- Image Details Overlay -->
    <LinearLayout
        android:id="@+id/image_details1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|start"
        android:orientation="vertical"
        android:visibility="gone"
        android:background="@color/black_overlay"
        android:padding="@dimen/overlay_padding">

        ...

    </LinearLayout>

    <!-- This FrameLayout insets its children based on system windows using
         android:fitsSystemWindows. -->
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

        <RelativeLayout
            android:id="@+id/fullscreen_content_controls"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:ignore="UselessParent">

            <LinearLayout
                android:id="@+id/fullscreen_content_controls_buttons"
                style="?metaButtonBarStyle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:background="@color/black_overlay"
                android:orientation="horizontal">

                ...
            </LinearLayout>

            <!-- Image Details Overlay -->
            <LinearLayout
                android:id="@+id/image_details2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@+id/fullscreen_content_controls_buttons"
                android:layout_alignParentStart="true"
                android:orientation="vertical"
                android:background="@color/black_overlay"
                android:padding="@dimen/overlay_padding">

             ...

            </LinearLayout>
        </RelativeLayout>
    </FrameLayout>

</FrameLayout>

I've tried positioning the snackbar at various elements on the screen as is but it always seems to hide behind the bottom navigation buttons when the application is not in full screen mode.

Flags used for full screen viewing:

mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
        | View.SYSTEM_UI_FLAG_FULLSCREEN
        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

What changes do I need to make to the layout to get the snackbar aligned correctly?

1

There are 1 best solutions below

0
On

I've found a solution.

When the application is in full screen mode, the snackbar is attached to the primary full screen content. R.id.fullscreen_content in this case.

When the application is not in full screen mode, the snackbar is attached to a new CoorderinatorLayout that is nested in the FrameLayout with android:fitsSystemWindows="true".

Would be nice to not have to manage it like this, but the solution works. Let me know if there is anything better.