Gnzlt
Gnzlt

Reputation: 4582

Snackbar inside layout

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();

Upvotes: 0

Views: 4008

Answers (2)

Rohit Jagtap
Rohit Jagtap

Reputation: 1670

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?

Upvotes: 0

Amarjit
Amarjit

Reputation: 4357

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>

Upvotes: 2

Related Questions