Android DialogFragment 底部弹框 去掉默认的左右下边距
DialogFragment默认左右下会有边距
这个需要重写一下onstart,关键属性,必须给设置背景图
class MyBottomDialogFragment : DialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val dialog = Dialog(requireContext()) dialog.setContentView(R.layout.layout_koi_box) // 设置底部弹出的样式 // dialog.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) // dialog.window?.setGravity(Gravity.BOTTOM) // 初始化和设置 RecyclerView val recyclerView1 = dialog.findViewById<RecyclerView>(R.id.rv_koi_box) val recyclerView2 = dialog.findViewById<RecyclerView>(R.id.rv_box_chat_list) setupRecyclerView(recyclerView1) setupRecyclerView(recyclerView2) return dialog } @Override override fun onStart() { super.onStart() // 获取当前 Dialog 对象的 Window val window = dialog!!.window if (window != null) { // 清除窗口的内边距和偏移量 window.decorView.setPadding(0, 0, 0, 0) window.setGravity(Gravity.BOTTOM) // 设置宽度为 MATCH_PARENT,高度自适应内容 window.setLayout( WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT ) // // 设置背景透明 window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) } }
}
原文地址:https://blog.csdn.net/weixin_41993823/article/details/135698347
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!