За допомогою нової бібліотеки компонентів матеріалів ви можете налаштувати форму компонента, використовуючи shapeAppearanceOverlayатрибут у вашому стилі ( Примітка: для цього потрібна версія 1.1.0 )
Просто скористайтеся BottomSheetDialogFragmentпереважним onCreateViewметодом, а потім визначте власний стиль для діалогів нижнього аркуша.
Визначте bottomSheetDialogThemeатрибут у styles.xmlтемі програми:
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
<item name="colorPrimary">@color/colorPrimary</item>
....
<item name="bottomSheetDialogTheme">@style/CustomBottomSheetDialog</item>
</style>
Тоді просто визначте свою улюблену форму за допомогою shapeAppearanceOverlay
<style name="CustomBottomSheetDialog" parent="@style/ThemeOverlay.MaterialComponents.BottomSheetDialog">
<item name="bottomSheetStyle">@style/CustomBottomSheet</item>
</style>
<style name="CustomBottomSheet" parent="Widget.MaterialComponents.BottomSheet">
<item name="shapeAppearanceOverlay">@style/CustomShapeAppearanceBottomSheetDialog</item>
</style>
<style name="CustomShapeAppearanceBottomSheetDialog" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSizeTopRight">16dp</item>
<item name="cornerSizeTopLeft">16dp</item>
<item name="cornerSizeBottomRight">0dp</item>
<item name="cornerSizeBottomLeft">0dp</item>
</style>

Ви можете отримати таку ж поведінку, перевизначивши цей метод у вашому BottomSheetDialogFragment(замість того, щоб додавати тему bottomSheetDialogThemeу вашій програмі):
@Override public int getTheme() {
return R.style.CustomBottomSheetDialog;
}
У цьому випадку ви використовуєте цей themeOverlay лише в одному, BottomSheetDialogFragmentа не у всій програмі.
Важлива примітка про РОЗШИРЕНУ ДЕРЖАВУ :
У розгорнутому стані BottomSheet має плоскі кути . Ви можете перевірити офіційний коментар у репозиторії github :
Наша команда дизайнерів твердо переконана, що закруглені кути вказують на прокручуваний вміст, тоді як плоскі кути вказують на відсутність додаткового вмісту. Таким чином, вони не хочуть, щоб ми додавали цю зміну за допомогою fitToContents.
Така поведінка забезпечується BottomSheetBehaviorі неможливо її замінити.
Однак є обхідне рішення -> ВІДМОВА: це може перестати працювати в наступних випусках !!
Ви можете додати a BottomSheetCallbackв BottomSheetDialogFragment:
@NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
((BottomSheetDialog)dialog).getBehavior().addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_EXPANDED) {
MaterialShapeDrawable newMaterialShapeDrawable = createMaterialShapeDrawable(bottomSheet);
ViewCompat.setBackground(bottomSheet, newMaterialShapeDrawable);
}
}
@Override public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
});
return dialog;
}
@NotNull private MaterialShapeDrawable createMaterialShapeDrawable(@NonNull View bottomSheet) {
ShapeAppearanceModel shapeAppearanceModel =
ShapeAppearanceModel.builder(getContext(), 0, R.style.CustomShapeAppearanceBottomSheetDialog)
.build();
MaterialShapeDrawable currentMaterialShapeDrawable = (MaterialShapeDrawable) bottomSheet.getBackground();
MaterialShapeDrawable newMaterialShapeDrawable = new MaterialShapeDrawable((shapeAppearanceModel));
newMaterialShapeDrawable.initializeElevationOverlay(getContext());
newMaterialShapeDrawable.setFillColor(currentMaterialShapeDrawable.getFillColor());
newMaterialShapeDrawable.setTintList(currentMaterialShapeDrawable.getTintList());
newMaterialShapeDrawable.setElevation(currentMaterialShapeDrawable.getElevation());
newMaterialShapeDrawable.setStrokeWidth(currentMaterialShapeDrawable.getStrokeWidth());
newMaterialShapeDrawable.setStrokeColor(currentMaterialShapeDrawable.getStrokeColor());
return newMaterialShapeDrawable;
}