0

i'm using this library 'com.mahc.custombottomsheetbehavior:googlemaps-like:0.9.1' to create a BottomSheet , every things is ok except layout_behavior ,when I add this,rendering problem appears

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/ma_bottom_sheet"
    android:background="@android:color/white"
    android:layout_gravity="bottom"
    app:behavior_hideable="true"
    app:behavior_peekHeight="100dp"
    app:layout_behavior="@string/BottomSheetBehaviorGoogleMapsLike"
   >

    <include
        layout="@layout/bottom_sheet_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"/>

</android.support.v4.widget.NestedScrollView>

the error log:

java.lang.ClassCastException: com.android.layoutlib.bridge.android.BridgeContext cannot be cast to android.app.Activity
at com.mahc.custombottomsheetbehavior.ScrollingAppBarLayoutBehavior.setStatusBarBackgroundVisible(ScrollingAppBarLayoutBehavior.java:177)
at com.mahc.custombottomsheetbehavior.ScrollingAppBarLayoutBehavior.init(ScrollingAppBarLayoutBehavior.java:109)
at com.mahc.custombottomsheetbehavior.ScrollingAppBarLayoutBehavior.onDependentViewChanged(ScrollingAppBarLayoutBehavior.java:78)
at android.support.design.widget.CoordinatorLayout.onChildViewsChanged(CoordinatorLayout.java:1335)
at android.support.design.widget.CoordinatorLayout$OnPreDrawListener.onPreDraw(CoordinatorLayout.java:1930)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:977)
at android.view.AttachInfo_Accessor.dispatchOnPreDraw(AttachInfo_Accessor.java:46)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:402)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.renderAndBuildResult(RenderSessionImpl.java:541)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.render(RenderSessionImpl.java:424)
at com.android.layoutlib.bridge.BridgeRenderSession.render(BridgeRenderSession.java:108)
at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:154)
at com.android.ide.common.rendering.api.RenderSession.render(RenderSession.java:136)
at com.android.tools.idea.rendering.RenderTask.lambda$renderInner$5(RenderTask.java:760)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Kennedy Kambo
  • 372
  • 4
  • 24
amir dt
  • 83
  • 2
  • 9
  • Looks like the library has a flaw and assumes a passed in Context is going to be an Activity. That's a common mistake by programmers who don't really understand Contexts. That's one of the reasons you shouldn't use random libraries on github – Gabe Sechan Apr 02 '18 at 14:47
  • Looking at the code- yup, that's exactly what he does. Either he needs to fix it, or you need to build his code from source and fix it yourself. I'd be wary of this library in general now- if he made that mistake once, where else does he make it, and what other basic things does he not get? – Gabe Sechan Apr 02 '18 at 14:50
  • Another way to fix it would be to instantiate the layout behavior by hand, instead of putting it in the xml. Then you can make sure the context you pass it is a direct Activity. That would hack around this problem, but you'd have to see what other ones exist. – Gabe Sechan Apr 02 '18 at 14:52
  • i'm trying your last suggestion,thanks for reply – amir dt Apr 02 '18 at 15:09

0 Answers0