我正在使用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() {
}
}
发布于 2020-07-24 11:01:11
在onStart回调中调用这个
override fun onStart() {
super.onStart()
dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
}
https://stackoverflow.com/questions/58251660
复制相似问题