Android Code Snippet StatusBar, NagivationBar and Background color all the same!

Hi Guys,

I am using the below code to change the color of the StatusBar, the NavigationBar and also change the Statusbar visibility flag....
I rekoned I could also change the Navigation bar visibility flag... so after almost 1h of searching, I found what value that flag is!!!

B4X:
Sub SetStatusNavigationBarColor(clr 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(clr))
window.RunMethod("setNavigationBarColor", Array(clr))
End If
If p.SdkVersion >= 23 Then
        jo = Root
jo.RunMethod("setSystemUiVisibility", Array(8192+16)) 'SYSTEM_UI_FLAG_LIGHT_STATUS_BAR + SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
End If
End Sub

This code allows for a continuous light color app background with dark text, icons and buttons.
 
Last edited:

fredo

Well-Known Member
Licensed User
Longtime User
Works great.

... with dark text, icons ...
02-11-2023_10-18-16.png



What is needed to set the textcolor to an individual color?
 

Alexander Stolte

Expert
Licensed User
Longtime User
I needed a way to display light and dark text and came up with the following 2 values:
B4X:
jo.RunMethod("setSystemUiVisibility",Array(8192+16)) 'Dark Text Color
jo.RunMethod("setSystemUiVisibility",Array(0x00000010)) 'Light Text Color

B4X:
Public Sub SetStatusNavigationBarColor(Root As B4XView,Color As Int,DarkText 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)
        window.RunMethod("addFlags", Array (0x80000000))
        window.RunMethod("clearFlags", Array (0x04000000))
        window.RunMethod("setStatusBarColor", Array(Color))
        window.RunMethod("setNavigationBarColor", Array(Color))
    End If
    If p.SdkVersion >= 23 Then
        jo = Root
        If DarkText Then
            jo.RunMethod("setSystemUiVisibility",Array(8192+16))
        Else
            jo.RunMethod("setSystemUiVisibility",Array(0x00000010))
        End If
    End If
End Sub
 

NanaCode

Member
Hi, I'm try to change my status bar color with this code but I there's an error message (undeclared variable 'p' used before it was assign and also unknown type 'phone' how do i fix this am using sdk vesion 33
 
Top