Android Tutorial Immersive Mode - hide the navigation bar

Status
Not open for further replies.
Immersive mode means full screen mode where the navigation bar is also hidden.

The user can bring back the bars by swiping near the edges.

The required steps are:

1. Call setSystemUiVisibility with the immersive flags. This is done in Activity_WindowFocusChanged.
2. Get the full display size and set the activity to that size.
3. Load the layout

Depends on JavaObject and Phone libraries.

Example is attached.
 

Attachments

  • ImmersiceMode.zip
    14.4 KB · Views: 1,610
Last edited:

Foz

Member
Licensed User
Longtime User
Thanks for this Erel, however there is a slight issue that 100%y is still fixed to the original size.
Obviously replacing 100%y with lv.Height resolves it (I have to store it, Activity.Height doesn't seem to adjust), it was just a gotcha for me :)
 

coslad

Well-Known Member
Licensed User
Longtime User
Hi

randomly when i change activity the app crash , at line 162 i have

B4X:
Sub Activity_WindowFocusChanged(HasFocus As Boolean)

log :

B4X:
Error occurred on line: 162 (Main)
java.lang.NullPointerException: Attempt to read from field 'anywheresoftware.b4a.BA b4a.casa.tablet.main.activityBA' on a null object reference
    at b4a.casa.tablet.main._activity_windowfocuschanged(main.java:629)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:357)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at b4a.casa.tablet.main.onWindowFocusChanged(main.java:185)
    at com.android.internal.policy.DecorView.onWindowFocusChanged(DecorView.java:1451)
    at android.view.View.dispatchWindowFocusChanged(View.java:10258)
    at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:1193)
    at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3605)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6119)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)


PS the errors seems happen only in debug mode
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
PS the errors seems happen only in debug mode
If it only happens in debug mode then ignore it. This is a problematic event as it fires in "unexpected" points.

Can you teach us how to implement this in B4A ? (So that the immersive mode is complete)
What is not complete?
 

coslad

Well-Known Member
Licensed User
Longtime User
"What is not complete?"

I try to explain , when the app is into immersive mode :

immersive_mode.jpg

if the user touch ed edge , the system bar reappears :

non_immersive_mode.jpg


I need to intercept the change to let my code resize the layout , to do this i find from Google development site :

To get notified of system UI visibility changes, register an View.OnSystemUiVisibilityChangeListener to your view. This is typically the view you are using to control the navigation visibility.
It's generally good practice to keep your UI in sync with changes in system bar visibility. For example, you could use this listener to hide and show the action bar in concert with the status bar hiding and showing.

B4X:
View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener
        (new View.OnSystemUiVisibilityChangeListener() {
    @Override
    public void onSystemUiVisibilityChange(int visibility) {
        // Note that system bars will only be "visible" if none of the
        // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
        if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
            // TODO: The system bars are visible. Make any desired
            // adjustments to your UI, such as showing the action bar or
            // other navigational controls.
        } else {
            // TODO: The system bars are NOT visible. Make any desired
            // adjustments to your UI, such as hiding the action bar or
            // other navigational controls.
        }
    }
});


but i can't make it works into B4A .

Any idea ?

Thanks
 
Status
Not open for further replies.
Top