1

我在刷 Snackbar 时发现了一个错误,比如这个代码https://github.com/nuuneoi/Lab-Android-DesignLibrary

1. 使用 appcompat-v7:23.0.0 在适当的上下文中将此代码添加到应用程序:

Snackbar
  .make(rootLayout, R.string.snackbar_text, Snackbar.LENGTH_LONG)
  .show();

2.视图必须在 AppBarLayout 中有一个工具栏,如下所示:

<android.support.design.widget.CoordinatorLayout
        android:id="@+id/rootLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary" />

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

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

3.在手机上滑动Snackbar。

4.App崩溃

java.lang.NullPointerException
            at android.support.design.widget.AppBarLayout$Behavior.onInterceptTouchEvent(AppBarLayout.java:729)
            at android.support.design.widget.AppBarLayout$Behavior.onInterceptTouchEvent(AppBarLayout.java:629)
            at android.support.design.widget.CoordinatorLayout.performIntercept(CoordinatorLayout.java:357)
            at android.support.design.widget.CoordinatorLayout.onInterceptTouchEvent(CoordinatorLayout.java:409)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1859)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2086)
            at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1533)
            at android.app.Activity.dispatchTouchEvent(Activity.java:2458)
            at android.support.v7.internal.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
            at android.support.v7.internal.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
4

2 回答 2

1

问题已解决,已在版本 23.0.1 中修复。支持库

于 2015-09-14T16:02:22.573 回答
0

您在 coordinatorlayout 中没有嵌入其他视图。因此,snackbar 没有任何其他视图可以协调。

于 2015-08-24T15:38:02.750 回答