The problem is that in versions below 5.0, when you close the bottom sheet, npe crashes, in version 5.0 and higher, everything is fine.

05-09 22:06:40.385 15759-15759/com.asgard.power E/AndroidRuntime: FATAL EXCEPTION: main java.lang.NullPointerException at android.support.design.widget.HeaderBehavior.onInterceptTouchEvent(HeaderBehavior.java:60) at android.support.design.widget.CoordinatorLayout.performIntercept(CoordinatorLayout.java:420) at android.support.design.widget.CoordinatorLayout.onInterceptTouchEvent(CoordinatorLayout.java:472) 

Also, if you click on any place in the tabs, and svapnut in any of the parties - also flies npe (I do not know if this information is useful).

As for the sample code, this is the most common bottom sheet of linear layouts and text files. Described in the main hml (not in the fragment), but is directly related to the recycleView located in the fragment.

Ps The application drops exactly on closing, when opening everything works as it should. On versions 5.0 and higher, everything generally works as it should.

 public class BehaviorController extends BottomSheetBehavior.BottomSheetCallback { private static BottomSheetBehavior behavior; public BehaviorController(BottomSheetBehavior behavior) { BehaviorController.behavior = behavior; } public static BottomSheetBehavior getBehavior(){ return behavior; } @Override public void onStateChanged(@NonNull final View bottomSheet, int newState) { switch (newState) { case BottomSheetBehavior.STATE_DRAGGING: bottomSheet.setVisibility(View.VISIBLE); break; case BottomSheetBehavior.STATE_COLLAPSED: /* bottomSheet.post(new Runnable() { @Override public void run() {*/ behavior.setState(BottomSheetBehavior.STATE_HIDDEN); behavior.setPeekHeight(0); /* } });*/ break; case BottomSheetBehavior.STATE_EXPANDED: // bottomSheet.setVisibility(View.INVISIBLE); behavior.setPeekHeight(400); break; } } @Override public void onSlide(@NonNull View bottomSheet, float slideOffset) { // behavior.setState(slideOffset > 0 ? behavior.STATE_EXPANDED : behavior.STATE_COLLAPSED); bottomSheet.setVisibility(View.VISIBLE); Log.d("Shit", "Slide" + behavior.getState()); } 

}

Activation code:

  private static void hideSheet(View bottomSheet, final BottomSheetBehavior behavior){ bottomSheet.post(new Runnable() { @Override public void run() { behavior.setState(BottomSheetBehavior.STATE_HIDDEN); } }); } private void initBottomSheetBehavior() { // RecycleFragment frag = (RecycleFragment )getSupportFragmentManager().findFragmentById(R.id.recyclefragment123456); frameSheet = (FrameLayout) findViewById(R.id.framesheet); coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinator); bottomSheet = coordinatorLayout.findViewById(R.id.framesheet); behavior = BottomSheetBehavior.from(bottomSheet); Log.d("Sheet", "behavior " + behavior); hideSheet(bottomSheet,behavior); RecycleFragment.getInstance().setContext(this); RecycleFragment.getInstance().setBehaviorSheet(behavior, frameSheet); behavior.setBottomSheetCallback(new BehaviorController(behavior)); } 
  • can you give the code? or how to close? - iFr0z
  • What version of compatibility library do you have? - VAndrJ
  • @VAndrJ compile 'com.android.support:appcompat-v7:24.0.0-alpha1' - Silento
  • The problem described by code.google.com/p/android/issues/detail?id=183166 may have returned Try a solution with 2, 3, and 40 answers. - VAndrJ
  • @VAndrJ did not help any of the answers, during the override, except that dispatchTouchEvent instead of the complete crash of the application - it froze in one state, not reacting to anything. - Silento

0