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() {
}
}
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.
call this in onStart callback
override fun onStart() {
super.onStart()
dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With