Android Question Resize Root B4XPages (Height Same Activity)

mt_heka

Member
I want add StatusBarHeight to main activity and root too but i have problem:

#In_Activity:
Sub Activity_Create(FirstTime As Boolean)
    Dim p As Phone
    If p.SdkVersion >= 4.4 Then
        Dim jo As JavaObject
        Dim window As JavaObject = jo.InitializeContext.RunMethod("getWindow", Null)
        window.RunMethod("addFlags", Array(Bit.Or(0x00000200, 0x08000000)))
        Activity.Height = Activity.Height + GetStatusBarHeight
        Activity.Color = Colors.Green 'for show
    End If
    
    Dim pm As B4XPagesManager
    pm.Initialize(Activity)
End Sub

Public Sub GetStatusBarHeight As Int
    Dim jo As JavaObject
    jo.InitializeContext
    Dim resources As JavaObject = jo.RunMethod("getResources", Null)
    Dim resId As Int = resources.RunMethod("getIdentifier", Array("status_bar_height", "dimen", "android"))
    If resId > 0 Then
        Return resources.RunMethod("getDimensionPixelSize", Array(resId))
    Else
        Return 0
    End If
End Sub

#In_B4XPages:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.Color = Colors.Red
End Sub

Result:
1745848627568.jpeg


But I want the Root to cover the entire Activity, and that green area should not be visible.
 
Solution
Thank you very much❤️, the problem is solved. ✅

#In_Activity:
Sub Process_Globals
    Public ActionBarHomeClicked As Boolean
    Public CorrectHeight As Int
    Public HeightChangedFired As Boolean
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim p As Phone
    If p.SdkVersion >= 4.4 Then
        Dim jo As JavaObject
        Dim window As JavaObject = jo.InitializeContext.RunMethod("getWindow", Null)
        window.RunMethod("addFlags", Array(Bit.Or(0x00000200, 0x08000000)))
        Activity.Height = Activity.Height + GetStatusBarHeight
        Activity.Color = Colors.Green 'for show
    End...

mt_heka

Member
Thank you very much❤️, the problem is solved. ✅

#In_Activity:
Sub Process_Globals
    Public ActionBarHomeClicked As Boolean
    Public CorrectHeight As Int
    Public HeightChangedFired As Boolean
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim p As Phone
    If p.SdkVersion >= 4.4 Then
        Dim jo As JavaObject
        Dim window As JavaObject = jo.InitializeContext.RunMethod("getWindow", Null)
        window.RunMethod("addFlags", Array(Bit.Or(0x00000200, 0x08000000)))
        Activity.Height = Activity.Height + GetStatusBarHeight
        Activity.Color = Colors.Green 'for show
    End If
    
    Dim pm As B4XPagesManager
    pm.Initialize(Activity)
    
    Wait For ime_HeightChanged (NewHeight As Int, OldHeight As Int)
    CorrectHeight = NewHeight
    HeightChangedFired = True
End Sub

Public Sub GetStatusBarHeight As Int
    Dim jo As JavaObject
    jo.InitializeContext
    Dim resources As JavaObject = jo.RunMethod("getResources", Null)
    Dim resId As Int = resources.RunMethod("getIdentifier", Array("status_bar_height", "dimen", "android"))
    If resId > 0 Then
        Return resources.RunMethod("getDimensionPixelSize", Array(resId))
    Else
        Return 0
    End If
End Sub

#In_B4XPages:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.Color = Colors.Red
    
    Dim start As Long = DateTime.Now
    Do While Main.HeightChangedFired = False And DateTime.Now < start + 500
        Sleep(50)
    Loop
    Root.Height = Main.CorrectHeight
End Sub
 
Upvote 0
Solution

mt_heka

Member
After that :
#In_B4XPages:
Sub SetIconBarsColor(DarkIcon As Boolean)
    Dim p As Phone
    If p.SdkVersion >= 21 Then
        Dim jo As JavaObject
        jo.InitializeContext
        Dim window As JavaObject = jo.RunMethodJO("getWindow", Null)
        Dim view As JavaObject = window.RunMethodJO("getDecorView",Null)

        If DarkIcon = True Then
            'Light style with Black icons and text
            view.RunMethod("setSystemUiVisibility",Array(Bit.Or(0x00002000,view.RunMethod("getSystemUiVisibility",Null)))) 'Light style with black icons and text
        Else
            'Dark style with White icons and text
            view.RunMethod("setSystemUiVisibility",Array(0))
        End If
    End If
End Sub

Sub SetStatusBarColor(Color As Int)
    Dim p As Phone
    If p.SdkVersion >= 21 Then
        Dim jo As JavaObject
        jo.InitializeContext
        Dim window As JavaObject = jo.RunMethodJO("getWindow", Null)
        window.RunMethod("addFlags", Array (0x80000000))
        window.RunMethod("clearFlags", Array (0x04000000))
        window.RunMethod("setStatusBarColor", Array(Color))
    End If
End Sub

Sub SetNavigationBarColor (Color As Int)
    Dim sdk As Phone
    If sdk.SdkVersion >= 21 Then
        Dim j1 As JavaObject
        j1.InitializeContext
        j1.RunMethodJO("getWindow",Null) _
            .RunMethod("setNavigationBarColor",Array (Color))
    End If
End Sub

this codes not work!:confused:
 
Upvote 0
Top