【Android】DialogFragmentの全画面表示
DialogFragmentを全画面表示し、起動元画面を背景に表示させる
Androidでダイアログを全画面で表示したいときの実装方法
XML
ルートのViewGroupの幅、高さをmatch_parentに設定する
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent" android:layout_height="match_parent"> (以下省略)
View
表示したいダイアログのonStart()の中で処理を追加
- windowのbackgroudにnullを設定
- windosに対してsetLayoutでMATCH_PARENTを設定
override fun onStart() { super.onStart() // 背景タップでダイアログを閉じない dialog!!.setCancelable(false) // 背景のDrawableをなくす(起動元画面が背景に見える状態) dialog!!.window!!.setBackgroundDrawable(null) // ダイアログのウィンドウサイズをMATCH_PARENTに設定 dialog!!.window!!.setLayout( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT) }