1

Want to move my snackbar above bottomnavigationview

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activityRootLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbarView"
                android:layout_width="match_parent"
                android:layout_height="@dimen/action_bar_size"
                android:background="@color/color_primary"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
        </FrameLayout>
    </com.google.android.material.appbar.AppBarLayout>

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/bottomNavigationLayout"
        android:layout_below="@+id/appBarLayout" />

    <LinearLayout
        android:id="@+id/bottomNavigationLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical">

        <View style="@style/FullDivider" />

        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottomNavigationView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:itemBackground="@android:color/white"
            app:itemIconTint="@drawable/selector_bottom_bar_item"
            app:itemTextColor="@color/blue"
            app:labelVisibilityMode="unlabeled"
            app:menu="@menu/main_navigation" />
    </LinearLayout>

    <com.mandarine.features.security.UnlockAppInputView
        android:id="@+id/unlockAppInputView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true" />
</RelativeLayout>

In MainActivity write smth like this:

container?.let {
    Snackbar.make(it, "No internet connection!", Snackbar.LENGTH_LONG).show()
}

But snackbar also display from bot of screen

Morozov
  • 4,968
  • 6
  • 39
  • 70

3 Answers3

0

Add one Layout above BottomNavigationView

Example:

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   android:id="@+id/myLayout"
 android:layout_above="@id/bottomNavigationView">
</android.support.design.widget.CoordinatorLayout>

then in Java code use:

final View viewPos = findViewById(R.id.myLayout);    
Snackbar.make(viewPos, R.string.snackbar_text, Snackbar.LENGTH_LONG)
                            .setAction(R.string.snackbar_action_undo, showListener)
                            .show();
Ganesh Pokale
  • 1,538
  • 1
  • 14
  • 28
0

I believe that the problem is in findSuitableParent function. As you can see on 232 line your container used as fallback, but then root view is found. Try to change your container to CoordinatorLayout and it will fix the issue.

Bracadabra
  • 3,609
  • 3
  • 26
  • 46
0

Resolve my problem with next solution:

private fun showNetworkMessage(isConnected: Boolean) {
    if (!isConnected) {
        val snack = Snackbar.make(
            findViewById(R.id.container),
            this.getText(R.string.warning_no_internet_connection), Snackbar.LENGTH_LONG
        )
        val params = snack.view.layoutParams as FrameLayout.LayoutParams
        params.setMargins(0, 0, 0, this.resources.getDimension(R.dimen.action_bar_size).toInt())
        snack.view.layoutParams = params
        snack.show()
    }
}

Where u can see i didn't use CoordinatorLayout.

Morozov
  • 4,968
  • 6
  • 39
  • 70