package com.mahc.custombottomsheet; import androidx.annotation.NonNull; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.viewpager.widget.ViewPager; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import androidx.appcompat.widget.Toolbar; import android.util.Log; import android.view.View; import android.widget.TextView; import com.mahc.custombottomsheetbehavior.BottomSheetBehaviorGoogleMapsLike; import com.mahc.custombottomsheetbehavior.MergedAppBarLayout; import com.mahc.custombottomsheetbehavior.MergedAppBarLayoutBehavior; public class MainActivity extends AppCompatActivity { int[] mDrawables = { R.drawable.cheese_3, R.drawable.cheese_3, R.drawable.cheese_3, R.drawable.cheese_3, R.drawable.cheese_3, R.drawable.cheese_3 }; TextView bottomSheetTextView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setTitle(" "); } /** * If we want to listen for states callback */ CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorlayout); View bottomSheet = coordinatorLayout.findViewById(R.id.bottom_sheet); final BottomSheetBehaviorGoogleMapsLike behavior = BottomSheetBehaviorGoogleMapsLike.from(bottomSheet); behavior.addBottomSheetCallback(new BottomSheetBehaviorGoogleMapsLike.BottomSheetCallback() { @Override public void onStateChanged(@NonNull View bottomSheet, int newState) { switch (newState) { case BottomSheetBehaviorGoogleMapsLike.STATE_COLLAPSED: Log.d("bottomsheet-", "STATE_COLLAPSED"); break; case BottomSheetBehaviorGoogleMapsLike.STATE_DRAGGING: Log.d("bottomsheet-", "STATE_DRAGGING"); break; case BottomSheetBehaviorGoogleMapsLike.STATE_EXPANDED: Log.d("bottomsheet-", "STATE_EXPANDED"); break; case BottomSheetBehaviorGoogleMapsLike.STATE_ANCHOR_POINT: Log.d("bottomsheet-", "STATE_ANCHOR_POINT"); break; case BottomSheetBehaviorGoogleMapsLike.STATE_HIDDEN: Log.d("bottomsheet-", "STATE_HIDDEN"); break; default: Log.d("bottomsheet-", "STATE_SETTLING"); break; } } @Override public void onSlide(@NonNull View bottomSheet, float slideOffset) { } }); MergedAppBarLayout mergedAppBarLayout = findViewById(R.id.mergedappbarlayout); MergedAppBarLayoutBehavior mergedAppBarLayoutBehavior = MergedAppBarLayoutBehavior.from(mergedAppBarLayout); mergedAppBarLayoutBehavior.setToolbarTitle("Title Dummy"); mergedAppBarLayoutBehavior.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { behavior.setState(BottomSheetBehaviorGoogleMapsLike.STATE_ANCHOR_POINT); } }); bottomSheetTextView = (TextView) bottomSheet.findViewById(R.id.bottom_sheet_title); ItemPagerAdapter adapter = new ItemPagerAdapter(this,mDrawables); ViewPager viewPager = (ViewPager) findViewById(R.id.pager); viewPager.setAdapter(adapter); behavior.setState(BottomSheetBehaviorGoogleMapsLike.STATE_ANCHOR_POINT); //behavior.setCollapsible(false); } }