Android Code Snippet Set Status bar colors

Discussion in 'Code Snippets' started by Emme Developer, Feb 19, 2018.

  1. Emme Developer

    Emme Developer Well-Known Member Licensed User

    A useful sub to set status bar color and foreground color, at runtime
    Code:
    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
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice