2016-06-09 52 views
7

在我的應用程序中,我有一個按下按鈕時出現的SnackBar。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> 
+0

[Snackbar和其他動畫在某些Android設備上停止工作]的可能重複(http://stackoverflow.com/questions/37221914/snackbar-and-other-animations-stopped-working-on-some-android-devices ) – Amagi82

回答

19

最後我跑到我的小吃吧的動畫還沒有工作。事實證明,我有另一個應用程序啓用了輔助功能,禁用某些動畫,如Snackbar動畫。

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

的檢查AccessibilityManager.isEnabled(),當啓用 任何輔助服務,它返回true。我剛剛檢查各種API 級別Snackbar工作正常,但沒有啓用輔助功能服務 。

在我的情況下,我安裝了GIF鍵盤並將其作爲可訪問性選項啓用。進入設置 - >輔助功能並關閉GIF鍵盤使動畫開始出現在我的應用程序中。

+9

什麼樣的延遲功能是?啊.. Google – VSG24

+1

在這種情況下,我該如何強制?我注意到,即使啓用了輔助功能設置,Inbox應用程序的快餐欄也可以使用正確的動畫。雖然我的應用程序沒有:| – Cesarsk

+0

@Cesarsk我只能猜測他們使用自定義Snackbar。 – egfconnor

0

最多的支持設計的版本23.4.0

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