I\'m trying to utilize ReplacementSpans to format the input in a EditText Field (without modifying the content):
public class SpacerSpan extends ReplacementS
CommonWare pointed me in the right direction.
It seems like ReplacementSpans
are rendered before any CharacterStyleSpan
are consulted [1]
A possible (but ugly) fix is to implement a custom ForegroundColorSpan
that extends MetricAffectingSpan
(MetricAffectingSpans are consulted before ReplacementSpans are drawn [1]).
public class FontColorSpan extends MetricAffectingSpan {
private int mColor;
public FontColorSpan(int color) {
mColor = color;
}
@Override
public void updateMeasureState(TextPaint textPaint) {
textPaint.setColor(mColor);
}
@Override
public void updateDrawState(TextPaint textPaint) {
textPaint.setColor(mColor);
}
}
I guess this is a bug that should be reported?
[1]http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.0.2_r1/android/text/TextLine.java#936