material-components-android
material-components-android copied to clipboard
[BottomSheet] Expanded bottom sheet with `fitToContents=false` is not full screen
Description:
Simple bottom sheet that starts expanded and has fitToContents=false:
class MyBottomSheet : BottomSheetDialogFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?) =
inflater.inflate(R.layout.fragment_second, container, false)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
(dialog as BottomSheetDialog).behavior.apply {
state = BottomSheetBehavior.STATE_EXPANDED
isFitToContents = false
}
}
}
will appear flying on top of the screen:
https://user-images.githubusercontent.com/3951580/195555156-25e88b5d-082d-4b7d-a1b8-08e9122d9f8f.mov
Expected behavior: Bottom sheet is full-screen, laid out with match_parent height
Source code: above
Minimal sample app repro: bottom-sheet.zip
Material Library version: 1.6.1
Hi @lwasyl, thanks for reporting this. Could you please attach a code sample or repo with any relevant code necessary to trigger this bug? It would be particularly helpful to see any XML layout files associated with the bottom sheet.
Ah disregard the above comment, I didn't notice that you attached a sample app.
I'm having the same problem. I've tried setting the design_bottom_sheet layout to MATCH_PARENT, but I get the same result as @lwasyl
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
Log.d(TAG, "onShow: onCreateDialog");
BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState);
dialog.setOnShowListener(dialog1 -> {
((BottomSheetDialog) dialog1).getBehavior().setFitToContents(false);
((BottomSheetDialog) dialog1).getBehavior().setState(BottomSheetBehavior.STATE_EXPANDED);
View bottomSheet = ((BottomSheetDialog) dialog1).findViewById(com.google.android.material.R.id.design_bottom_sheet);
if (bottomSheet != null) {
bottomSheet.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
}
});
// Do something with your dialog like setContentView() or whatever
return dialog;
}
any updates on this? have exactly same issue
Also have same issue.. any solutions? or updates?
Having the same issue.
Not sure whether this is a bug or intended to be like this. Here is what helped me: https://stackoverflow.com/a/76283458/6657837
My onViewCreated method:
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
View parentLayout = ((BottomSheetDialog) getDialog()).findViewById(com.google.android.material.R.id.design_bottom_sheet);
ViewGroup.LayoutParams layoutParams = parentLayout.getLayoutParams();
layoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
parentLayout.setLayoutParams(layoutParams);
}