Android Question StatusBar Color.

Eme Fibonacci

Well-Known Member
Licensed User
Longtime 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
Longtime 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

B4X founder
Staff member
Licensed User
Longtime 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
Longtime 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
Longtime 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

mfstuart

Active Member
Licensed User
Longtime 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
If I set the "clr" = White, how do I set the TextColor of the statusbar to Black?
Because setting it to white, sets the text to white as well. Therefore you can't read anything on the StatusBar.

Thanx,
Mark Stuart
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Because setting it to white, sets the text to white as well. Therefore you can't read anything on the StatusBar.
Mark: This thread link may answer your question. Definitely worth checking:
 
Upvote 0

mfstuart

Active Member
Licensed User
Longtime User
Mark: This thread link may answer your question. Definitely worth checking:
It can be done. Google Gmail does it when you touch the Search panel, that panel animates and changes the status bar color to gray and the text to black. Actually, the text color is already black. Then you press the left pointing arrow, it animates back again, and the status bar color changes to white (with the text color black).
 
Upvote 0
Top