Android Question Text color when using TextWriter

TonyVerberne

Member
Licensed User
Longtime User
Is it possible to control the color of text using TextWriter.WriteLine and then view it in a message box?
 
I think that there is some confusion. TextWriter has nothing to do with the text appearance. It converts string characters to bytes and writes them to a stream.
Thanks Erel but is there a way to control text appearance in the way that I have described? I have written a shopping list app for my own use actually. It works quite well (I think) but would benefit from being able to change text color when writing the list so that I can distinguish items in different parts of the store.
Having fun anyway. Tony
 
Upvote 0
Hi Erel I took up your suggestion. I have used the following code inside a spinner:

Code: Copy
rsb.Initialize
    rs.Initialize("{R}{T}{Blue}{U}Fruit{R}{T}{Blue}{U}{R}{T}{Blue}{U}Aisle{U}{Blue}{T}{R}")
    rs.Color2(Colors.Blue,"{Blue}")
    rs.RelativeSize2(1.5, "{R}")
    rs.Typeface2("serif", "{T}")
    rs.Underscore2("{U}")
    rs.Color2(Colors.Red, "{Red}")
    rs.Style2(rs.STYLE_BOLD_ITALIC, "{BI}")

rsb.Append(rs)
    Text1 = SpinnerFruit.selectedItem
    outFile.Initialize(File.OpenOutput(File.DirRootExternal, "Text1.txt", True))
outFile.WriteLine(rs)
    outFile.Close

When I look at the richstring (rs) it's formatted as I want it in colour. But when I write the string to my text file it becomes plain unformatted text.

Is it because WriteLine can't handle the formatted text?
 
Upvote 0
But when I write the string to my text file it becomes plain unformatted text.
I think that there is some confusion. TextWriter has nothing to do with the text appearance.

So, when you save the file and load it back you need to use build the richstring with your text again to display it formatted i think (dont have used richstring)

You cannot store a formatted richstring to a textfile.
 
Upvote 0
This is a serious limitation of TextWriter. Is there another way to write formatted text to a file I wonder?

Thanks for you comments DonManfred!
 
Upvote 0
Since you are saving individual formatted lines, you could use a MAP to save the formatted lines, for example:
Code: Copy
myMap.Put("1", rs) 'Where "1" is the line number or any other value you want to use as a key.
And to retrieve the formatted line:
Code: Copy
myLabel.Text = myMap.Get("1")

That's an idea.
 
Upvote 0
Back
Top