繁体   English   中英

SnackBar出现动画

[英]SnackBar appear animation

在我的应用程序中,我有一个SnackBar,当按下按钮时会出现。

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

在上面的代码中,v是在FloatingActionButton的onClick事件中获得的视图。

在默认的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>

我最终遇到了Snackbar动画,但也无法正常工作。 原来,我有另一个启用了辅助功能选项的应用程序,它禁用了某些动画,例如Snackbar动画。

参见克里斯的帖子#5: https : //code.google.com/p/android/issues/detail?id=206416

检查是AccessibilityManager.isEnabled(),当启用任何辅助功能服务时返回true。 我只是检查了各种API级别,而Snackbar在未启用辅助功能的情况下工作正常。

在我的情况下,我安装了GIF键盘并将其作为辅助功能选项启用。 进入设置->可访问性并关闭GIF键盘,动画开始出现在我的应用中。

将支持设计的版本提高到23.4.0

compile 'com.android.support:design:23.4.0'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM