Android Question StatusBar Color.

Eme Fibonacci

Well-Known Member
Licensed User
Easy way to change the color of StaturBar?

Maybe java in line?

how use this in b4a?

B4X:
public abstract void setStatusBarColor (int color)

Thank you.
 

somed3v3loper

Well-Known Member
Licensed User
This code is almost like this

B4X:
Public Sub setStatusBarColor (color As Int)

it does nothing by itself .
If you find a library or java code that does change statusbar color we will try to help you convert it to B4A
 
Upvote 0

Erel

Administrator
Staff member
Licensed User
Here:
B4X:
Sub SetStatusBarColor(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))
   End If
End Sub
 
Upvote 0

Eme Fibonacci

Well-Known Member
Licensed User
Here:
B4X:
Sub SetStatusBarColor(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))
   End If
End Sub


Perfect!!

And it works with " Theme.Holo " too!

Thank you.
 
Upvote 0

Douglas Farias

Expert
Licensed User
Here:
B4X:
Sub SetStatusBarColor(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))
   End If
End Sub

hi erel.
sory to ask here on a old topic.
i m trying this code now here, and i have a question.

how can i make to this code works 2 times on the same activity?
i have a splash yellow, i want show the splash in yellow and statusbar too, later the splash visible = false i want change the color of statusbar again.
i m trying but it stay with yellow, dont change the color on the second time.
 
Upvote 0
Top