SnackBar появляется анимация

В моем приложении у меня есть SnackBar, который появляется при нажатии кнопки.

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

В приведенном выше коде v — это представление, полученное в событии onClick FloatingActionButton.

В SnackBar по умолчанию он отображается с анимацией скольжения вверх. В моем приложении анимация не отображается. Он просто появляется без анимации. Есть ли способ заставить анимацию показывать?

Вот файл макета

<?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>

person Sudarshan Sunder    schedule 09.06.2016    source источник
comment
Похоже, исправление уже готово issuetracker.google.com/issues/37092972#comment37.   -  person alashow    schedule 03.08.2018


Ответы (2)


В итоге я столкнулся с тем, что анимация моей закусочной также не работала. Оказалось, что у меня было другое приложение, в котором были включены параметры доступности, которые отключают определенные анимации, такие как анимация Snackbar.

См. сообщение Криса №5: https://code.google.com/p/android/issues/detail?id=206416

Проверкой является AccessibilityManager.isEnabled(), которая возвращает true, когда включена любая служба специальных возможностей. Я только что проверил различные уровни API. Снэкбар работает нормально без включенной службы специальных возможностей.

В моем случае у меня была установлена ​​GIF-клавиатура и включена в качестве опции доступности. Перейдя в «Настройки» -> «Специальные возможности» и отключив GIF-клавиатуру, анимация начала появляться в моем приложении.

person egfconnor    schedule 24.06.2016
comment
Как я должен заставить это в этих случаях? Я заметил, что закусочная в приложении Inbox работает с правильной анимацией даже при включенных настройках специальных возможностей. В то время как мое приложение не :| - person Cesarsk; 23.03.2017
comment
@Cesarsk Я могу только догадываться, что они используют собственную закусочную. - person egfconnor; 24.03.2017
comment
К вашему сведению, у меня такая же проблема, и дело не только в клавиатуре GIF. Для меня это был LastPass, поэтому я думаю, что если у вас включены ЛЮБЫЕ службы, он сломается -_- - person Louis Tsai; 19.09.2017

Увеличьте версию вашего дизайна поддержки до 23.4.0

compile 'com.android.support:design:23.4.0'
person jmarkstar    schedule 09.06.2016