Android Question Title Bar - how to colour some text ?

amorosik

Expert
Licensed User
On the title bar of my app I have strings that inform the user about the app status
One of these information is Connected / Disconnected
Something like
"Connected 10 tel:01234567 Wifi:OK .."
I would like to be able to change only the text (or background) color only of the word Connected in the title bar
How do I write 'Connected' with a different color (or background) from the rest of the title bar text?
 

TILogistic

Expert
Licensed User
Longtime User
?



B4X:
    Dim cs As CSBuilder
    cs.Initialize
    cs.Color(Colors.Red)
    cs.Append("Hello ")
    cs.Bold
    cs.Color(Colors.Blue)
    cs.Append("Colorfull ")
    cs.Pop.Pop 'two pops: the first removes the green color and the second removes the bold style
    cs.Append("World!")
    cs.PopAll
    B4XPages.SetTitle(Me, cs)
 
Last edited:
Upvote 2

TILogistic

Expert
Licensed User
Longtime User
demo actionbar and statusbar
B4X:
Private Sub Button1_Click
    SetStatusBarColor(Rnd(0xFF000000, 0))
    SetActionBarColor(Rnd(0xFF000000, 0))
End Sub

Public Sub SetActionBarColor(Color As Int)
    Dim cd As ColorDrawable
    cd.Initialize(Color, 0)
    Dim actionbar As JavaObject = B4XPages.GetManager.ActionBar
    If actionbar.IsInitialized Then
        actionbar.RunMethod("setBackgroundDrawable", Array(cd))
    End If
End Sub

Public 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

 

Attachments

  • 1.gif
    252 KB · Views: 168
Last edited:
Upvote 1

amorosik

Expert
Licensed User


Excellent, may thanks
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…