0

Is it possible to show a Snackbar message inside a layout, like show it inside a RelativeLayout instead of show it at the bottom of the screen?

I've tried to use a referenced view to a RelativeLayout but it doesn't work.

Snackbar.make(relativeLayoutView, snackbarText, Snackbar.LENGTH_LONG).show();
Gnzlt
  • 4,383
  • 2
  • 22
  • 24

2 Answers2

2

You can do this by making a new layout CoordinatorLayout inside relative layout and set custom width and height to CoordinatorLayout layout.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="100dip">

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end|bottom"
            android:layout_margin="16dp"
            android:src="@drawable/add"
            app:layout_behavior="com.demotest.FloatingActionButtonBehavior" />

    </android.support.design.widget.CoordinatorLayout>
</RelativeLayout>
Amarjit
  • 4,327
  • 2
  • 34
  • 51
0

I don't think you can show a snackbar anywhere on the screen but only at the bottom. According to the standards it should be at the bottom.

As per the documentation says,

"Snackbars provide lightweight feedback about an operation. They show a brief message at the bottom of the screen on mobile and lower left on larger devices."

https://developer.android.com/reference/android/support/design/widget/Snackbar.html

If you still want to do this, checkout,

How can you adjust Android SnackBar to a specific position on screen

How do I change an Android Snackbar's initial alignment from bottom to top?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Rohit Jagtap
  • 1,660
  • 1
  • 14
  • 12