Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Dim background in bottomsheet using BottomSheetDialogFragment

Tags:

android

I am using BottomSheetDialogFragment to show bottom sheet. How can I remove the dim background?

I have made the transparent background but when the bottom sheet pops up the background below it dims.

class ClearDataBottomSheet : BottomSheetDialogFragment {

private lateinit var contentView: View

constructor() {

}

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
}

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
    val dialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog

    dialog.setCancelable(false)
    dialog.setOnShowListener { dialog ->
        val d = dialog as BottomSheetDialog
        val bottomSheet = d.findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet)
        BottomSheetBehavior.from(bottomSheet!!).state = BottomSheetBehavior.STATE_EXPANDED
    }

    // Do something with your dialog like setContentView() or whatever
    return dialog
}

override fun setupDialog(dialog: Dialog, style: Int) {
    super.setupDialog(dialog, style)
    contentView = View.inflate(context, R.layout.clear_data_bottom_sheet, null)
    dialog.setContentView(contentView)
    initview()

    //tomake background transparent
    try {
        context?.let { ContextCompat.getColor(it, android.R.color.transparent) }?.let { (contentView.parent as View).setBackgroundColor(it) }
    } catch (e: Exception) {
    }
}

private fun initview() {
}

}

like image 486
Ankush Kapoor Avatar asked Oct 05 '19 19:10

Ankush Kapoor


People also ask

How can I dim the background when Bottomsheet is displayed without using dialog?

Using the Interface - onSlide which as a parameter slideOffSet of type float , can be used to dim the background. The new offset of this bottom sheet within [-1,1] range. Offset increases as this bottom sheet is moving upward.


Video Answer


1 Answers

call this in onStart callback

override fun onStart() {
    super.onStart()
    dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
}
like image 74
user4097210 Avatar answered Sep 28 '22 02:09

user4097210