Sets The Pinnacle Of Collapsed Bottom Sheet, Past Times Calling Setpeekheight() Method

Posted on
In lasp instance of BottomSheet, I implement a OnClickListener of background to expand in addition to collapse the bottom sheet. Without this, user cannot expand the bottom sail if collapsed, because bottom sail convey tiptop of 0 past times default. If yous desire yous tin set the tiptop of collapsed bottom sheet, past times calling setPeekHeight() method.

This video present how:


MainActivity.java

package com.blogspot.android_er.androidbottomsheet;  import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.BottomSheetBehavior; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.LinearLayout; import android.widget.TextView;  world shape MainActivity extends AppCompatActivity {      LinearLayout backgroundLayout;     View bottomSheet;     someone BottomSheetBehavior bottomSheetBehavior;     TextView textPrompt;     TextView textSDK;      /*     Build.VERSION.SDK_INT:     The user-visible SDK version of the framework;     its possible values are defined inwards Build.VERSION_CODES.     https://developer.android.com/reference/android/os/Build.VERSION_CODES.html      */     int sdk_int = Build.VERSION.SDK_INT;      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          textSDK = (TextView)findViewById(R.id.textSDK);         textSDK.setText("Running SDK_INT: " + sdk_int);          textPrompt = (TextView)findViewById(R.id.prompt);         backgroundLayout = (LinearLayout)findViewById(R.id.backgroundlayout);          bottomSheet = findViewById(R.id.bottomsheet);         bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);         bottomSheetBehavior.setBottomSheetCallback(bottomSheetCallback);          bottomSheetBehavior.setPeekHeight(150);          /*         backgroundLayout.setOnClickListener(new View.OnClickListener() {             @Override             world void onClick(View v) {                 switch (bottomSheetBehavior.getState()){                     instance BottomSheetBehavior.STATE_COLLAPSED:                         bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);                         break;                     instance BottomSheetBehavior.STATE_EXPANDED:                         bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);                         break;                 }             }         });         */     }      BottomSheetBehavior.BottomSheetCallback bottomSheetCallback =             novel BottomSheetBehavior.BottomSheetCallback(){         @Override         world void onStateChanged(@NonNull View bottomSheet, int newState) {             switch (newState){                 instance BottomSheetBehavior.STATE_COLLAPSED:                     textPrompt.setText("COLLAPSED");                     break;                 instance BottomSheetBehavior.STATE_DRAGGING:                     textPrompt.setText("DRAGGING");                     break;                 instance BottomSheetBehavior.STATE_EXPANDED:                     textPrompt.setText("EXPANDED");                     break;                 instance BottomSheetBehavior.STATE_HIDDEN:                     textPrompt.setText("HIDDEN");                     break;                 instance BottomSheetBehavior.STATE_SETTLING:                     textPrompt.setText("SETTLING");                     break;                 default:                     textPrompt.setText("unknown...");             }         }          @Override         world void onSlide(@NonNull View bottomSheet, float slideOffset) {          }     }; }