Hello,
I try to adapt the Serial/Bluetooth chat example with colored text in the txtLog window (EditText type).
Here is an extract of the code in the ChatActivity module (LogMessage Sub is modified):
The result of this code is that the last line in the txtLog window has the correct color, but the previous lines become black. It seems like the text format of the previous lines disappears in the command rs.Initialize(txtLog.Text & ......).
The time stamp itself works correctly.
Do you know how I can keep the text color of all the lines in the txtLog window?
Thank you for your help.
I try to adapt the Serial/Bluetooth chat example with colored text in the txtLog window (EditText type).
Here is an extract of the code in the ChatActivity module (LogMessage Sub is modified):
B4X:
[...]
Sub AStream_NewData (Buffer() As Byte)
LogMessage("You", BytesToString(Buffer, 0, Buffer.Length, "UTF8"))
End Sub
[...]
Sub btnSend_Click
AStream.Write(txtInput.Text.GetBytes("UTF8"))
txtInput.SelectAll
txtInput.RequestFocus
LogMessage("Me", txtInput.Text)
End Sub
Sub LogMessage(From As String, Msg As String)
'ORIGINAL txtLog.Text = txtLog.Text & From & ": " & Msg & CRLF
' TEST Time Stamp
DateTime.TimeFormat = "HH:mm:ss.SSS"
Dim timeNow As String
timeNow = DateTime.Time(DateTime.Now)
' TEST TextColor
Dim rs As RichString
rs.Initialize(txtLog.Text & "{TxtColor}" & "(" & timeNow & ") " & From & ": " & Msg & "{TxtColor}" & CRLF)
'TEST rs.Initialize("{TxtColor}" & "(" & timeNow & ") " & From & ": " & Msg & "{TxtColor}")
If From = "Me" Then rs.Color2(Colors.Blue, "{TxtColor}")
If From = "You" Then rs.Color2(Colors.Red, "{TxtColor}")
txtLog.Text = rs
'TEST txtLog.Text = txtLog.Text & rs & CRLF
'ORIGINAL
txtLog.SelectionStart = txtLog.Text.Length
End Sub
The result of this code is that the last line in the txtLog window has the correct color, but the previous lines become black. It seems like the text format of the previous lines disappears in the command rs.Initialize(txtLog.Text & ......).
The time stamp itself works correctly.
Do you know how I can keep the text color of all the lines in the txtLog window?
Thank you for your help.