一、前言:
在继承AppCompatDialogFragment()方法中的dialog弹窗一直有灰色背景,去不掉;
766c928ef6b0b6359ba4d0fac7b45b2.png override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
dialog?.window?.attributes?.apply {
width = WindowManager.LayoutParams.MATCH_PARENT //ViewGroup.LayoutParams.MATCH_PARENT
height = WindowManager.LayoutParams.WRAP_CONTENT //182.dp
gravity = Gravity.BOTTOM
dimAmount = 0f//1、调节灰色背景透明度[0,1],默认0.5
isCancelable = true
}
// dialog?.window?.setBackgroundDrawableResource(android.R.color.transparent)//添加背景透明色
// dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) //2、去掉灰色背景
dialog?.window?.setWindowAnimations(R.style.dialogBottomInOut)
}
二、解决:
demo参考:https://gitee.com/lyyon/MyFragmentDialog
1、方法一:
添加dimAmount 属性:
dimAmount = 0.0f //调节灰色背景透明度[0,1],默认0.5
2、方法二:
添加clearFlags
dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) //去掉灰色背景
源码:
//调用
btn_play.onClickWithSpring(1.05f) {
PartyFunPlayDialog.newInstance().apply {
this.controllerContext = ctx
show()
}
}
open class PartyFunPlayDialog : UkiDialogFragment() {
private val binding by viewBinding(DialogPartyFunPlayViewBinding::bind)
//点击送礼
var clickGift: ((people: MemberBundle) -> Unit)? = null
val personalModel by lazy {
ViewModelProvider(this).get(PersonalModel::class.java)
}
var people: MemberBundle? = null
companion object {
const val TYPE = "type" //0-在麦列表,1-不在麦列表
fun newInstance(): PartyFunPlayDialog {
return PartyFunPlayDialog().apply {
// if (people.pendantList == null) {//此步防止member 使用 putParcelable 时带有空列表数据导致崩溃
// people.pendantList = mutableListOf()
// }
// arguments = Bundle().apply {
// putParcelable(MEMBER, people)
// putBoolean(IS_OWNER_VIEW, isOwnerView)
// }
}
}
}
override fun createView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return inflater.inflate(R.layout.dialog_party_fun_play_view, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// people = arguments?.getParcelable(MEMBER)
// familyInfo = arguments?.getParcelable(FAMILY_INFO)
with(binding){
tvTitle.text = "你好啊,很好"
// var list = mapOf<Int>()
// var myAdapter = GameAdapter(R.layout.item_gift_album_view, null)
// var linearLayoutManager = LinearLayoutManager(mContext)
// linearLayoutManager.orientation = LinearLayoutManager.HORIZONTAL
// rvList.layoutManager = linearLayoutManager
// rvList.adapter = myAdapter
// rvList?.setNewData(list)
}
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
dialog?.window?.attributes?.apply {
width = WindowManager.LayoutParams.MATCH_PARENT //ViewGroup.LayoutParams.MATCH_PARENT
height = WindowManager.LayoutParams.WRAP_CONTENT //182.dp
gravity = Gravity.BOTTOM
//dimAmount = 0f//1、调节灰色背景透明度[0,1],默认0.5
isCancelable = true
}
// dialog?.window?.setBackgroundDrawableResource(android.R.color.transparent)//添加背景透明色
// dialog?.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) //2、去掉灰色背景
dialog?.window?.setWindowAnimations(R.style.dialogBottomInOut)
}
}
网友评论