Android Code Snippet Set Status bar colors

A useful sub to set status bar color and foreground color, at runtime
B4X:
Sub SetStatusBarColor(clr As Int)
 Dim p As Phone
 If p.SdkVersion > 20 Then

 'Background color
  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))
 
  Dim view As JavaObject = window.RunMethodJO("getDecorView",Null)

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