This example show how to detect and check if your app run in multi window mode, target Android N with Multi-Window Support, by calling isInMultiWindowMode() and override onMultiWindowModeChanged() methods.
if(isInMultiWindowMode()){ textPrompt.setText("onCreate run In Multi Window Mode "); }else{ textPrompt.setText("onCreate run NOT In Multi Window Mode "); } }
@Override public void onMultiWindowModeChanged(boolean isInMultiWindowMode) { super.onMultiWindowModeChanged(isInMultiWindowMode);
if(isInMultiWindowMode){ textPrompt.setText("It is In Multi Window Mode "); }else{ textPrompt.setText("It is NOT In Multi Window Mode "); } } }
In lasp example of BottomSheet, I implement a OnClickListener of background to expand and collapse the bottom sheet. Without this, user cannot expand the bottom sheet if collapsed, because bottom sheet have height of 0 by default. If you want you can set the height of collapsed bottom sheet, by calling setPeekHeight() method.
/* Build.VERSION.SDK_INT: The user-visible SDK version of the framework; its possible values are defined in Build.VERSION_CODES. https://developer.android.com/reference/android/os/Build.VERSION_CODES.html */ int sdk_int = Build.VERSION.SDK_INT;
/* backgroundLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { switch (bottomSheetBehavior.getState()){ case BottomSheetBehavior.STATE_COLLAPSED: bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); break; case BottomSheetBehavior.STATE_EXPANDED: bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); break; } } }); */ }
BottomSheetBehavior.BottomSheetCallback bottomSheetCallback = new BottomSheetBehavior.BottomSheetCallback(){ @Override public void onStateChanged(@NonNull View bottomSheet, int newState) { switch (newState){ case BottomSheetBehavior.STATE_COLLAPSED: textPrompt.setText("COLLAPSED"); break; case BottomSheetBehavior.STATE_DRAGGING: textPrompt.setText("DRAGGING"); break; case BottomSheetBehavior.STATE_EXPANDED: textPrompt.setText("EXPANDED"); break; case BottomSheetBehavior.STATE_HIDDEN: textPrompt.setText("HIDDEN"); break; case BottomSheetBehavior.STATE_SETTLING: textPrompt.setText("SETTLING"); break; default: textPrompt.setText("unknown..."); } }
@Override public void onSlide(@NonNull View bottomSheet, float slideOffset) {
With the help from the Android Design Support Library, you can implement a number of important material design components to all developers and to all Android 2.1 or higher devices.
This example show how to implement Bottom Sheets with help of Android Design Support Library.
/* Build.VERSION.SDK_INT: The user-visible SDK version of the framework; its possible values are defined in Build.VERSION_CODES. https://developer.android.com/reference/android/os/Build.VERSION_CODES.html */ int sdk_int = Build.VERSION.SDK_INT;
backgroundLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { switch (bottomSheetBehavior.getState()){ case BottomSheetBehavior.STATE_COLLAPSED: bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); break; case BottomSheetBehavior.STATE_EXPANDED: bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); break; } } });
}
BottomSheetBehavior.BottomSheetCallback bottomSheetCallback = new BottomSheetBehavior.BottomSheetCallback(){ @Override public void onStateChanged(@NonNull View bottomSheet, int newState) { switch (newState){ case BottomSheetBehavior.STATE_COLLAPSED: textPrompt.setText("COLLAPSED"); break; case BottomSheetBehavior.STATE_DRAGGING: textPrompt.setText("DRAGGING"); break; case BottomSheetBehavior.STATE_EXPANDED: textPrompt.setText("EXPANDED"); break; case BottomSheetBehavior.STATE_HIDDEN: textPrompt.setText("HIDDEN"); break; case BottomSheetBehavior.STATE_SETTLING: textPrompt.setText("SETTLING"); break; default: textPrompt.setText("unknown..."); } }
@Override public void onSlide(@NonNull View bottomSheet, float slideOffset) {