0

I'm trying to have a full screen DialogFragment with the ability to show / hide status and navigation bars when tapping the screen. Here is the DialogFragment

class FullScreenFragment : DialogFragment() {

   override fun onCreate(savedStateInstance: Bundle?) {
       super.onCreate(savedStateInstance)

      setStyle(STYLE_NORMAL, R.style.Theme_FullScreenDialog) 
   }

   override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
      binding = FragmentTemplateBinding.inflate(inflater, container, false)
      return binding.root
   }

  override fun onActivityCreated(savedInstanceState: Bundle?) {
    super.onActivityCreated(savedInstanceState)

    activity?.window?.decorView?.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    or View.SYSTEM_UI_FLAG_FULLSCREEN
                    or View.SYSTEM_UI_FLAG_IMMERSIVE)  
  }
}

And the related theme is,

<style name="Theme.FullScreenDialog" parent="Theme.MaterialComponents.Dialog">
    <item name="windowNoTitle">true</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:fitsSystemWindows">false</item>

    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:textColor">@android:color/white</item>
</style>

Having done these steps, I can still see navigation bar. Status bar seems to be hiding. Any idea what could possibly be the issue?

Renjith
  • 3,457
  • 5
  • 46
  • 67

1 Answers1

1

Note to moderator: I deleted this answer from a different question. The answer is most pertinent to this question.

I was able to enter immersive mode in a (full-screen) DialogFragment without changing FLAG_NOT_FOCUSABLE by setting up my theme this way:

<style name="AppTheme" parent="Theme.MaterialComponents.NoActionBar">
    <item name="android:dialogTheme">@style/Dialog</item>
    ...
</style>
<style name="Dialog" parent="ThemeOverlay.MaterialComponents.Dialog">
    <!-- windowBackground removes padding in inherited background -->
    <item name="android:windowBackground">?attr/colorSurface</item>
    <item name="android:windowIsFloating">false</item>
    <item name="android:windowNoTitle">true</item>
</style>

I then enter immersive mode with this (note dialog?.window?.decorView rather than activity?.window?.decorView):

dialog?.window?.decorView?.let(ViewCompat::getWindowInsetsController)?.apply {
    systemBarsBehavior =
        WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
    hide(WindowInsetsCompat.Type.systemBars())
}

Klaus
  • 724
  • 6
  • 14