Android Question Immersive mode issues

techknight

Well-Known Member
Licensed User
Longtime User
I have read, re-read, and read again all the confusing circular threads that seem to point back to one another via links in this forum.

So basically, The immersive mode works, but it leaves a grey bar where the nav buttons went on the side of my phone. I cant get rid of this bar and make the activity script fill the screen.

I am NOT changing orientations, I have the app set to work in landscape mode only at all times, The nav buttons and title bar all go away, but it leaves that stupid grey bar.

I tried the IME code that was posted, I tried some other code and I cannot get it to go away.

any ideas? All my UI code is in the layout script.
 

techknight

Well-Known Member
Licensed User
Longtime User
I fixed it. Probably not the correct way, but here is how I did it:

B4X:
Sub ForceImmersiveMode
    Dim jo As JavaObject = Activity
    jo.RunMethod("setSystemUiVisibility", Array As Object(5894)) '3846 - non-sticky
    Activity.Width = GetRealWidth
    Activity.Height = GetRealHeight
    Activity.RemoveAllViews
    Activity.LoadLayout("1")
    Activity.Invalidate
End Sub

Sub Activity_WindowFocusChanged(HasFocus As Boolean)
    If HasFocus Then
        ForceImmersiveMode
    End If
End Sub

Sub GetRealWidth As Int
   Dim p As Phone
   If p.SdkVersion >= 17 Then
     Dim jo As JavaObject
     jo = jo.InitializeContext.RunMethodJO("getWindowManager", Null).RunMethod("getDefaultDisplay", Null)
     Dim metrics As JavaObject
     metrics.InitializeNewInstance("android.util.DisplayMetrics", Null)
     jo.RunMethod("getRealMetrics", Array(metrics))
     Return metrics.GetField("widthPixels")
   Else
     Return GetDeviceLayoutValues.Width
   End If
End Sub

Sub GetRealHeight As Int
   Dim p As Phone
   If p.SdkVersion >= 17 Then
     Dim jo As JavaObject
     jo = jo.InitializeContext.RunMethodJO("getWindowManager", Null).RunMethod("getDefaultDisplay", Null)
     Dim metrics As JavaObject
     metrics.InitializeNewInstance("android.util.DisplayMetrics", Null)
     jo.RunMethod("getRealMetrics", Array(metrics))
     Return metrics.GetField("heightPixels")
   Else
     Return GetDeviceLayoutValues.Height
   End If
End Sub

Under Activity_Create, I put:
B4X:
    ForceImmersiveMode
    Sleep(1000)

Gives it time to reinitialize all the controls. This works for me because the main page will never change. Layouts may change, but the main activity will not.
 
Upvote 0
Top