Android Question B4XPages Top Bar with immersion mode?

doncx

Active Member
Licensed User
Longtime User
Is it possible to display and use the B4XPages Top Bar while in Android immersion mode?

That would be sweet.
 
Solution
B4XPage code:
B4X:
Sub Class_Globals
    Private RootBase As B4XView
    Private Root As B4XView
    Private xui As XUI
End Sub

Public Sub Initialize
    
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    RootBase = Root1
    Root = xui.CreatePanel("Root")
    RootBase.AddView(Root, 0, Main.TitleHeight, RootBase.Width, RootBase.Height - Main.TitleHeight)
    Root.LoadLayout("1")
End Sub

Main code:
B4X:
Sub Process_Globals
    Public ActionBarHomeClicked As Boolean
    Public TitleHeight As Int
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim p As Phone
    If p.SdkVersion >= 28 Then
        Dim ctxt As JavaObject
        ctxt.InitializeContext
        ctxt.RunMethodJO("getWindow"...

doncx

Active Member
Licensed User
Longtime User
No. I do indeed want that to disappear.

I'm referring to the B4XPages Top Bar. When I tried immersive mode it disappeared and I'd like for it to show in my pages.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

doncx

Active Member
Licensed User
Longtime User
Thanks, Erel -

That works, with one problem: The Action Bar appears but the top of my layouts disappear behind it. I can update my layouts if necessary (there's dozens) but I see there's a way to add margin/padding with setOnApplyWindowInsetsListener. This one's a bit over my head.

Can you suggest the best way to get the top of my layout out from under the Action Bar?

Thank you
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4XPage code:
B4X:
Sub Class_Globals
    Private RootBase As B4XView
    Private Root As B4XView
    Private xui As XUI
End Sub

Public Sub Initialize
    
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    RootBase = Root1
    Root = xui.CreatePanel("Root")
    RootBase.AddView(Root, 0, Main.TitleHeight, RootBase.Width, RootBase.Height - Main.TitleHeight)
    Root.LoadLayout("1")
End Sub

Main code:
B4X:
Sub Process_Globals
    Public ActionBarHomeClicked As Boolean
    Public TitleHeight As Int
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
    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
    Dim NavBarHeight As Int = GetNavBarHeight(Activity)
    Dim ScreenHeight As Int = GetRealSize.Height
    TitleHeight = ScreenHeight - 100%y - NavBarHeight
    Log("TitleHeight: " & TitleHeight)
    Activity_WindowFocusChanged(True)
    Dim lv As LayoutValues = GetRealSize
    Dim jo As JavaObject = Activity
    jo.RunMethod("setBottom", Array(lv.Height))
    jo.RunMethod("setRight", Array(lv.Width))
    Activity.Height = lv.Height
    Activity.Width = lv.Width
    Dim pm As B4XPagesManager
    pm.Initialize(Activity)
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")
    lv.Scale = 100dip / 100
    Return lv
End Sub

Sub GetNavBarHeight(v As View) As Int
    Dim jo As JavaObject = v
    Dim insets As JavaObject = jo.RunMethod("getRootWindowInsets", Null)
    If insets.IsInitialized = False Then Return 0
    Dim WindowInsetsType As JavaObject
    WindowInsetsType.InitializeStatic("android.view.WindowInsets.Type")
    Dim navbar As JavaObject = insets.RunMethod("getInsets", Array(WindowInsetsType.RunMethod("navigationBars", Null)))
    Return navbar.GetField("bottom")
End Sub
 

Attachments

  • ImmersiveMode.zip
    14.6 KB · Views: 27
Upvote 0
Solution
Cookies are required to use this site. You must accept them to continue using the site. Learn more…