Android Question Change color of CSBuilder text in a label

RogerGCollin

Member
Licensed User
So I have made a label that acts as a button when pressed and want to change the color of the text in the label when selected. However the text is made using CSBuilder with a FontAwesome icon on the top and small text underneath. The obvious btn2.textColor = Colors.Red does not work and I guess that is because this relates to straight text and not rich text produced by CSBuilder.
While I can just rebuild the text with CSBuilder every time, this is an inelegant way to just change color. Does anyone know if there is a better solution?

CSBuilder code below. In Sub btn1_Click the btn.textColor.Colors.Red has no effect

'This event will be called once, before the page becomes visible.
B4X:
 Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
   
    'Set up menu icons
    cs.Initialize.color(0xFF92BF2C).Size(30).Typeface(Typeface.FONTAWESOME).VerticalAlign(0dip).Append(Chr(0xF015)).Pop. _
    Typeface(Typeface.DEFAULT_BOLD).Append(CRLF).Size(12).Append("Home").PopAll
    btn1.Text = cs
    cs.Initialize.color(0xFFE7E7E7).Size(30).Typeface(Typeface.FONTAWESOME).VerticalAlign(0dip).Append(Chr(0xF155)).Pop. _
    Typeface(Typeface.DEFAULT_BOLD).Append(CRLF).Size(12).Append("New Package").PopAll
    btn2.Text = cs
    cs.Initialize.color(0xFFE7E7E7).Size(30).Typeface(Typeface.FONTAWESOME).VerticalAlign(0dip).Append(Chr(0xF1DA)).Pop. _
    Typeface(Typeface.DEFAULT_BOLD).Append(CRLF).Size(12).Append("History").PopAll
    btn3.Text = cs
   
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
B4X:
Sub btn1_Click
    pnl1.BringToFront
    btn1.textColor = Colors.Red
End Sub
 

Attachments

  • 5Of10.zip
    10.5 KB · Views: 133
Last edited:

Mahares

Expert
Licensed User
Longtime User
You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Here it is Roger:
You can use the XUI Views library or just XUI.
B4X:
Private xui As XUI  'declared in Globals
B4X:
Sub btn1_Click
    pnl1.BringToFront
    Dim b4xb1 As B4XView=btn1    'you can also declare in global, but I do not want to confuse you for now
    b4xb1.SetColorAndBorder(xui.Color_Red,5dip,xui.Color_Cyan,5dip)  'you can change these colors
End Sub
Please note that the community prefers that you use code tags when you post code to make it easy to read, and especially when you stress elegance like you do
 
Last edited:
Upvote 0

RogerGCollin

Member
Licensed User
The above code does not work. It changes the label background and border but not the text, which is what I wanted to do. Can you just change the text color and nothing else?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
he above code does not work. It changes the label background and border but not the text, which is what I wanted to do
I thought you were changing the label color. I don't think there is a way to change the textcolor of CSBuilder without rebuilding the CSBuilder which you already thought of, unless someone has a better idea. It really does not take any overhead to rebuild the CSBuilder:
B4X:
Sub btn1_Click
    pnl1.BringToFront
    cs.Initialize.color(xui.Color_Blue).Size(30).Typeface(Typeface.FONTAWESOME).VerticalAlign(0dip).Append(Chr(0xF015)).Pop. _
    Typeface(Typeface.DEFAULT_BOLD).Append(CRLF).Size(12).Append("Home").PopAll
    btn1.Text = cs
End Sub
 
Upvote 0
Top