Changing the Font Color in a Listview?

Stepdragon

Member
Licensed User
Longtime User
I'm working on a themeable app. I have a listview, which I set the background color, scrollingbackgroundcolor, and singlelinelayout.label.textcolor to specific values progmatically.

Then I have a routine which changes the theme, and resets all these values.

The two backgrounds change, but not the text color. Note that I'm not trying to have anything different between entries, I want them all to change.

I have also tried the following:
Removing and Re-adding all entries
Toggling the Visible Property
Toggling the Enabled Property
Invalidating the view

For some reason I can't get the color of the font to change beyond the original setting. Is this by design? Can it be done? of will I have to go ahead and just use a scrollview (I do it in other parts of the app, but this is more convenient)

Thanks
 

Stepdragon

Member
Licensed User
Longtime User
My theme scripting is a bit messy... so bear with me...

(I am going to redo my theme so it is a list of object referencing Colors.ARGB(), but right now this works, and I'll make that change when I'm done working on this arch that I'm on)

Even though I coded it this way, it does work with everything else, so I'm tempted to say that it has to do with something other than my code, but you know, I'm not the best coder in the world, so here's my code for you to dissect until we figure out what's wrong.

Creating my themes:
B4X:
   Type color(A As Int, R As Int, B As Int, G As Int)
   Type Theme(Name As String, B As color, PB As color,  FC As color, SFC As color,PBH As color,mbg As color)
   Dim Themes As List
   Themes.Initialize
   Dim CurrentTheme As Int

   Dim TD As Theme
   TD.Initialize
   TD.Name = "Dark"
   TD.B.A = 255
   TD.B.R = 28
   TD.B.B = 28
   TD.B.G = 28
   TD.PB.A = 255
   TD.PB.R = 56
   TD.PB.G = 56
   TD.PB.B = 56
   TD.FC.A = 215
   TD.FC.R = 104
   TD.FC.G = 213
   TD.FC.B = 214
   TD.SFC.A = 255
   TD.SFC.R = 150
   TD.SFC.g = 20
   TD.SFC.b = 5
   TD.PBH.a = 255
   TD.PBH.R = 87
   TD.PBH.g = 87
   TD.PBH.b = 87
   TD.mbg.A = 255
   TD.mbg.R = 44
   TD.mbg.g = 44
   TD.mbg.b = 44
   
   Themes.Add(TD)
   
   Dim TN As Theme
   TN.Initialize
   TN.Name = "Night"
   TN.B.A = 255
   TN.B.R = 27
   TN.B.B = 38
   TN.B.G = 39
   TN.PB.A = 255
   TN.PB.R = 71
   TN.PB.G = 34
   TN.PB.B = 69
   TN.FC.A = 255
   TN.FC.R = 216
   TN.FC.G = 123
   TN.FC.B = 255
   TN.SFC.A = 255
   TN.SFC.R = 150
   TN.SFC.g = 20
   TN.SFC.b = 5
   TN.PBH.A = 255
   TN.PBH.R = 0
   TN.PBH.g = 0
   TN.PBH.b = 0
   TN.mbg.A = 255
   TN.mbg.R = 72
   TN.mbg.g = 35
   TN.mbg.b = 52
   
   Themes.Add(TN)
   
   CurrentTheme = Themes.IndexOf(TD)

Sub to set colors:
B4X:
Sub ThemeColor(ColorName As String) As Object
   Dim CT As Theme
   CT.Initialize
   CT = Themes.get(CurrentTheme)
   If ColorName = "Background" Then Return Colors.ARGB(CT.b.a,CT.b.R,CT.B.g,CT.B.b)
   If ColorName = "PostBack" Then Return Colors.ARGB(CT.pb.a,CT.pb.R,CT.pB.g,CT.pB.b)
   If ColorName = "Font1" Then Return Colors.ARGB(CT.fc.a,CT.fc.R,CT.fc.g,CT.fc.b)
   If ColorName = "Font2" Then Return Colors.ARGB(CT.sfc.a,CT.sfc.R,CT.sfc.g,CT.sfc.b)
   If ColorName = "Highlight" Then Return Colors.ARGB(CT.pbh.a,CT.pbh.R,CT.pbh.g,CT.pbh.b)
   If ColorName = "MenuBack" Then Return Colors.ARGB(CT.mbg.a,CT.mbg.R,CT.mbg.g,CT.mbg.b)   
End Sub

Code Used in Context:
B4X:
Sub SetColors   
   BoardsLV.Clear
   BoardsLV.Color = ThemeColor("MenuBack")
   BoardsLV.ScrollingBackgroundColor = ThemeColor("MenuBack")
   BoardsLV.SingleLineLayout.Label.TextColor = ThemeColor("Font1")
   
   AddItems
End Sub


Now, even though this is a workaround, it does work in every other situation and control in my app, including the other listview properties... I'm wondering why its not working here...

Doubt it matters but: Switch Theme code
B4X:
Sub MenuTheme_click
   If CurrentTheme < Themes.Size-1 Then
      CurrentTheme = CurrentTheme + 1 
   Else
      CurrentTheme = 0
   End If
   
   SetColors
End Sub
 
Last edited:
Upvote 0

Stepdragon

Member
Licensed User
Longtime User
I only set SingleLineLayout.Label.TextColor once in the entire app (just searched)
I am using both SingleLineLayouts and TwoLineLayouts, but I'm only setting the color of the SingleLineLayout (the other color is the same on all themes, default android, so I don't ever bother setting it)

obvious questions usually lead to the answer so there's no harm in asking.

I'm still stumped though...
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Put a Log command after setting the color and see if it actually changes.
Log(BoardsLV.SingleLineLayout.Label.TextColor)
EDIT:
Can you see what ThemeColor("Font1") is returning? It seems to return an object, but color is probably 'Long' type. Can you do a Log on that and check?
 
Last edited:
Upvote 0

Stepdragon

Member
Licensed User
Longtime User
When First Running the activity
B4X:
Before - -1
After - -680995370

When Changing the theme
B4X:
Before - -680995370
After - -2589697

However, there is no visible change unless I close and reopen the activity...
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Upvote 0

Stepdragon

Member
Licensed User
Longtime User
ah well, I'll switch it over to a scrollview (only a few more lines of code)

Thanks for helping with that though. I hadn't seen that post when I was searching.
 
Upvote 0
Top