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
    Sub SetStatusBarColor(clr As Int)
    Dim p As Phone
    If p.SdkVersion > 20 Then

    'Background color
      Dim jo As JavaObject
    Dim window As JavaObject = jo.RunMethodJO("getWindow"Null)
    "addFlags"Array (0x80000000))
    "clearFlags"Array (0x04000000))
    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
    DroidLyon, Jmu5667, lazreg and 6 others like this.
  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