Android Question Fullscreen for One B4XPage Only

Javaneh

Member
Hi everyone,

Is there a way to make a specific page fullscreen while keeping the other pages non-fullscreen?
I know I could use a separate activity, but I prefer to keep all the pages within the same activity.
Thank you!
 

Javaneh

Member
I've added an example of also hiding the status bar. If you want a full screen = immersive mode, then search for immersive mode. It will be difficult to get it working properly with multiple pages.


Erel I tried making one of my pages immersive using the following code:

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root
    Root.LoadLayout("l2")
  
    SetUp
  
End Sub

Sub SetUp
    Dim p As Phone
    If p.SdkVersion >= 28 Then
        Dim ctxt As JavaObject
        ctxt.InitializeContext
        ctxt.RunMethodJO("getWindow", Null).RunMethodJO("getAttributes", Null).SetField("layoutInDisplayCutoutMode", 1)
    End If
    GetRealSize
    CallSubDelayed2(Main, "Activity_WindowFocusChanged",True)
    Dim lv As LayoutValues = GetRealSize
    Dim jo As JavaObject = Root
    jo.RunMethod("setBottom", Array(lv.Height))
    jo.RunMethod("setRight", Array(lv.Width))
    Root.Height = lv.Height
    Root.Width = lv.Width
    Dim pm As B4XPagesManager
    pm.Initialize(Root)
End Sub

Sub GetRealSize As LayoutValues
    Dim lv As LayoutValues
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim WindowManager As JavaObject = ctxt.RunMethodJO("getSystemService", Array("window"))
    Dim display As JavaObject = WindowManager.RunMethod("getDefaultDisplay", Null)
    Dim point As JavaObject
    point.InitializeNewInstance("android.graphics.Point", Null)
    display.RunMethod("getRealSize", Array(point))
    lv.Width = point.GetField("x")
    lv.Height = point.GetField("y")
    Log(lv.Height)
    lv.Scale = 100dip / 100
    Return lv
End Sub

And I placed this code in the activity hosting the pages:

B4X:
Sub Activity_WindowFocusChanged(HasFocus As Boolean)
    Log(HasFocus)
    If HasFocus Then
        Try
            Dim jo As JavaObject = Activity
            Sleep(300)
            jo.RunMethod("setSystemUiVisibility", Array As Object(5894)) '3846 - non-sticky
        Catch
            Log("error")
            'Log(LastException) 'This can cause another error
        End Try 'ignore
      
    End If
End Sub

The issue is that a white section appears at the bottom of the screen, and the image doesn’t fully stretch to fullscreen:

photo_2024-12-31_23-03-11.jpg
photo_2024-12-31_23-07-24.jpg


Also, I didn’t do anything specific to hide the status bar; I just used the ImmersiveMode code.

Additionally, could you guide me on how to revert the settings to the previous state and cancel ImmersiveMode for other pages when exiting this specific page?

Thank you!
 
Upvote 0
Top