2016-06-09 23 views
7

In meiner App habe ich eine SnackBar, die erscheint, wenn eine Taste gedrückt wird.SnackBar erscheint Animation

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

Im obigen Code ist v die Ansicht, die im onClick-Ereignis eines FloatingActionButtons abgerufen wird.

In der Standard-SnackBar erscheint es mit einer aufschiebbaren Animation. In meiner App wird die Animation nicht angezeigt. Es erscheint nur ohne Animation. Gibt es eine Möglichkeit, die Animation zu erzwingen?

Hier ist das Layout-Datei

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

Mögliche Duplikate von [Snackbar und andere Animationen funktionieren nicht mehr auf einigen Android-Geräten] (http://StackOverflow.com/questions/37221914/snackbar-and-other-animations-stopped-working-on-some-android-devices) – Amagi82

Antwort

19

landete ich laufen in meine Snackbar Animationen nicht auch arbeiten. Es stellte sich heraus, dass ich eine andere App hatte, die Zugriffsmöglichkeiten aktiviert hatte, die bestimmte Animationen wie die Snackbar-Animation deaktivierten.

Siehe Beitrag # 5 von Chris: https://code.google.com/p/android/issues/detail?id=206416

Die Prüfung wird AccessibilityManager.isEnabled(), die true zurückgibt, wenn jede Zugänglichkeit Dienst aktiviert ist. Ich habe nur auf verschiedene API Ebenen überprüfen Snackbar funktioniert gut, ohne einen Service für Barrierefreiheit aktiviert.

In meinem Fall hatte ich GIF Keyboard installiert und als eine Option für den Zugriff aktiviert. Unter Einstellungen -> Eingabehilfen und Ausschalten der GIF-Tastatur wurden die Animationen in meiner App angezeigt.

+9

Was für eine verzögerte Funktion ist das? Ah .. Google – VSG24

+1

Wie soll ich das in diesen Fällen erzwingen? Ich habe festgestellt, dass die Snackbar der Inbox-App auch bei aktivierten Eingabehilfeneinstellungen mit der richtigen Animation funktioniert. Während meine App nicht: | – Cesarsk

+0

@Cesarsk Ich kann nur vermuten, dass sie eine benutzerdefinierte Snackbar verwenden. – egfconnor

0

Up der Version Ihrer Unterstützung Design 23.4.0

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