Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SnackBar appear animation

In my app I have a SnackBar that appears when a button is pressed.

Snackbar.make(v, "Enter valid data", Snackbar.LENGTH_SHORT).show();

In the above code, v is the view obtained in the onClick event of a FloatingActionButton.

In the default SnackBar, it appears with a sliding up animation. In my app, the animation doesn't show. It just appears without any animation. Any way to force the animation to show?

Here's the layout file

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout               
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:id="@+id/loginRootView"
android:layout_height="match_parent"
android:background="@drawable/back_pattern">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/loginToolbar"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:background="@color/primary"
        app:popupTheme="@style/AppTheme.PopupOverlay" />


</android.support.design.widget.AppBarLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.CardView
        android:id="@+id/loginCard"
        android:layout_width="match_parent"
        android:layout_height="290dp"
        android:layout_centerInParent="true"
        android:layout_marginBottom="5dp"
        android:layout_marginEnd="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginStart="5dp"
        android:layout_marginTop="5dp"
        app:cardCornerRadius="3dp"
        app:cardElevation="4dp"
        app:cardUseCompatPadding="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <android.support.design.widget.TextInputLayout
                android:id="@+id/loginNumber"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginRight="80dp"
                android:layout_marginTop="40dp">

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Mobile Number"
                    android:inputType="phone"
                    android:textColor="#666666" />
            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:id="@+id/loginPassword"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/loginNumber"
                android:layout_centerInParent="true"
                android:layout_marginRight="80dp"
                android:layout_marginTop="20dp">

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Password"
                    android:inputType="textPassword"
                    android:textColor="#666666" />
            </android.support.design.widget.TextInputLayout>

            <TextView
                android:id="@+id/loginForgotPassword"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/loginPassword"
                android:layout_below="@+id/loginPassword"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="15dp"
                android:text="Forgot Password?" />

        </RelativeLayout>

    </android.support.v7.widget.CardView>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/loginButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/loginCard"
        android:layout_marginRight="20dp"
        android:layout_marginTop="-43dp"
        android:background="#12af1c"
        android:src="@drawable/ic_done_white_36dp" />

    <TextView
        android:id="@+id/loginSignUpLink"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/loginCard"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:text="New user? Register here."
        android:textSize="18sp" />

</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
like image 401
Sudarshan Sunder Avatar asked Jun 09 '16 14:06

Sudarshan Sunder


People also ask

What is the difference between toast and snackbar?

Snackbars contain a single line of text directly related to the operation performed. They may contain a text action, but no icons. Toasts (Android only) are primarily used for system messaging. They also display at the bottom of the screen, but may not be swiped off-screen.

What is a snackbar in UI?

Snackbars inform users of a process that an app has performed or will perform. They appear temporarily, towards the bottom of the screen. They shouldn't interrupt the user experience, and they don't require user input to disappear.

What is a snackbar in Android?

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. Snackbars appear above all other elements on screen and only one can be displayed at a time.


1 Answers

I ended up running into my Snackbar animations not working also. It turned out to be that I had another app which had accessibility options enabled which disables certain animations such as the Snackbar animation.

See post #5 by Chris: https://code.google.com/p/android/issues/detail?id=206416

The check is AccessibilityManager.isEnabled(), which returns true when any accessibility service is enabled. I've just check on various API levels Snackbar is working fine without an accessibility service enabled.

In my case I had GIF Keyboard installed and enabled as an accessbility option. Going into Settings -> Accessibility and turning off GIF Keyboard made the animations start appearing in my app.

like image 51
egfconnor Avatar answered Nov 15 '22 20:11

egfconnor