Mark Mark - 5 months ago 36
Android Question

Can you detect whether an application is in immersive mode in Fragment.onCreateView?

In a fragment I have implemented a

GestureDetector.SimpleOnGestureListener
so that I can enter/exit immersive mode when
onSingleTapUp
is detected.

A
FragmentStatePagerAdapter
is used to move between these fragments on swipe left/right. If you enter immersive mode then swipe to a new fragment the UI remains in immersive mode.

However, in the
onCreateView
method of the new fragment I need to detect whether the UI is in immersive mode to when creating my listener.

I have tried calling
getSystemUiVisibility()
on the new view but this returns
SYSTEM_UI_FLAG_VISIBLE
.

Is there a method for detecting whether the application is in immersive mode from any view or fragment regardless of whether that initiated the transition to immersive mode?

Answer

@Mark, it sounds like you may have gotten it resolved based on my previous comment: use a View owned by the Activity to call getSystemUiVisibility() rather than the Fragment.

Comments