我正在使用BottomSheetDialogFragment来显示底部工作表。 如何删除暗淡的背景?
我已经制作了透明背景,但是当底页弹出时,其下方的背景变暗。
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() {
}
}
答案 0 :(得分:2)
在onStart回调中调用它
dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)