I am working on an application in which a user can post content in a feed. In my text editor (used for layout) the text color is gray. However, when the user enters a hash tag, for example. #help I need to color this text black by type, so when the user types “#”, the text should be painted black until a new word begins, then the color of the text should return to gray.
I am trying to use a text observer and a stretched string for color.
Here is what I did with textwatcher onTextChanged
@Override public void onTextChanged(CharSequence s, int start, int before, int count) { //Remove Text watcher to prevent infinite look mTextField.removeTextChangedListener(contentFieldWatcher); String startChar = null; startChar = Character.toString(s.charAt(start)); Li(getClass().getSimpleName(), "CHARACTER OF NEW WORD: " + startChar); if (startChar.equals("
tag method
private void tagCheck(String s, int start, int end) { mSpannable.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.black_colour)), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); }
mSpannable is spammy.
The problem with this method is that '#' is displayed as startChar, however, when the user enters the next character, character or letter, it shows as startChar. Where, as if the user typed santa - s', startChar remains. Therefore, the problem I am facing is how to dynamically color the text when the user enters a hashtag.
So simple letters work correctly, however, when you use a symbol, it is not. I hope the question is clear. I looked at it for several days and it all got foggy :)