我正在使用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() {
}
}
<item name="android:backgroundDimEnabled">false</item>
来设置BottomSheet主题的样式,可以实现相同的效果。 - Ryan Amaral