Android Question Text color when using TextWriter

Discussion in 'Android Questions' started by TonyVerberne, May 16, 2015.

  1. TonyVerberne

    TonyVerberne Member Licensed User

    Is it possible to control the color of text using TextWriter.WriteLine and then view it in a message box?
     
  2. eurojam

    eurojam Well-Known Member Licensed User

    TextWriter.WriteLine writes text to the underlying stream, like a external textfile. you can pass the line anyway to a message box where you can set the color to the desired color. but directly setting the color is not possible, I think...
    see http://www.b4x.com/android/help/files.html#textwriter
     
    TonyVerberne likes this.
  3. TonyVerberne

    TonyVerberne Member Licensed User

    Thanks. Its a pity that isn't possible.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    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.
     
  5. TonyVerberne

    TonyVerberne Member Licensed User

    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
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    TonyVerberne likes this.
  7. TonyVerberne

    TonyVerberne Member Licensed User

  8. TonyVerberne

    TonyVerberne Member Licensed User

    Hi Erel I took up your suggestion. I have used the following code inside a spinner:

    Code:
    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?
     
  9. DonManfred

    DonManfred Expert Licensed User

    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.
     
  10. TonyVerberne

    TonyVerberne Member Licensed User

    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!
     
  11. NJDude

    NJDude Expert Licensed User

    Since you are saving individual formatted lines, you could use a MAP to save the formatted lines, for example:
    Code:
    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:
    myLabel.Text = myMap.Get("1")
    That's an idea.
     
    TonyVerberne and thedesolatesoul like this.
  12. TonyVerberne

    TonyVerberne Member Licensed User

    Thanks - I'll give it a try.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice