1

Update: This behaviour is happening due to using Theme.Material3, if I change that to Theme.Design only for the bottomsheet it fills the parent but this takes us to another problem which is the colours now are different, since I am using material you which gets the colours from the phones theme, I can't set the colours manually for the content of the bottom sheet.

I can't show the width of the bottomSheetFragDialog to match_parent, there is some sort of strange margin from the start and the end.

These screenshots I am getting from a new proj, no single line of code is written, so nothing could be changed. Portrait Image

Landscape Image

I have added a placeholder content for the purpose of the demonstration, here is the xml code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="0dp"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="Hello, World!"
    android:textSize="100sp"
    android:gravity="center"/>


<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="Hello, World!"
    android:textSize="100sp"
    android:gravity="center"/>
</LinearLayout>

Nothing in the xml layout is important, I am just putting anything.

Here is the Kotlin code that shows the sheet:

TestSheet().show(supportFragmentManager, TestSheet::class.java.canonicalName)

Also here is the code in the class TestSheet:

class TestSheet : BottomSheetDialogFragment() {

override fun onCreateView(
    inflater: LayoutInflater,
    container: ViewGroup?,
    savedInstanceState: Bundle?
): View? {
    val v = inflater.inflate(R.layout.sheet_test, container, false)
    (dialog as BottomSheetDialog).let {
        it.behavior.state = BottomSheetBehavior.STATE_EXPANDED
        it.behavior.skipCollapsed = true
        it.behavior.isDraggable = true
        dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
        dialog?.window?.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
    }
    return v
}
}

My issue: I can't get the BottomSheetFragmentDialog to be in fullscreen when the phone is rotated into landscape, instead I get what you see in the pic below, strange layout margin that I have not set. Thanks!

Mohammad Elsayed
  • 1,885
  • 1
  • 20
  • 46

1 Answers1

0

I'm using simple BottomsheetDialog and working just fine.

Define these styles in styles.xml

<style name="BottomSheet">
        <!--        <item name="android:background">@drawable/bg_rounded_bottom_24</item>-->
        <item name="android:background">@android:color/transparent</item>
    </style>

    <style name="BaseBottomSheetDialog" parent="Theme.MaterialComponents.Light.BottomSheetDialog">
        <item name="android:windowIsFloating">false</item>
        <item name="bottomSheetStyle">@style/BottomSheet</item>
        <item name="android:backgroundDimEnabled">true</item>
    </style>

    <style name="BottomSheetDialogTheme" parent="BaseBottomSheetDialog">
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:navigationBarColor">@color/white</item>
        <item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">true</item>
    </style>

In your activity or fragment

bottomSheet = BottomSheetDialog(this, R.style.BaseBottomSheetDialog)
bottomSheet.setContentView(view)
bottomSheet.show()

Now, in your manifest, define this attribute in activity tag,

android:configChanges="screenSize|orientation|uiMode"
Dev4Life
  • 2,328
  • 8
  • 22