Hi i have multiple autocomplete text view with space tokenizer and use ReplacementSpan for background color change in each contacts
my custom replacement code is
public class MyForgroudSpan : ReplacementSpan
{
public override void Draw(Canvas canvas, ICharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint)
{
var rect = new RectF(x , top, x + paint.MeasureText(text, start, end)+8, bottom);
paint.Color = Android.Graphics.Color.ParseColor("#E5E5E6");
canvas.DrawRect(rect, paint);
paint.Color = Android.Graphics.Color.Black;
int xPos = Java.Lang.Math.Round(x + (8 / 2));
int yPos = (int)((canvas.Height / 2) - ((paint.Descent() + paint.Ascent()) / 2));
canvas.DrawText(text, start, end, xPos, yPos, paint);
}
public override int GetSize(Paint paint, ICharSequence text, int start, int end, Paint.FontMetricsInt fm)
{
return Java.Lang.Math.Round(paint.MeasureText(text, start, end))+8;
}
}
i set spannable string here
SpannableStringBuilder ssb = new SpannableStringBuilder(Text.trim());
ssb.SetSpan(new MyForgroudSpan(), x, x + c.Length, SpanTypes.ExclusiveExclusive);
its ok when multiple auto complete textview have single line but it come to multiple line means it overlap each text
please see the screens
1.single line
2.multiline image
When i use y value like this
canvas.DrawText(text, start, end, xPos, y, paint);
If you are using your ReplacementSpan only to change the background color you could as well simply use a BackgroundColorSpan:
The overlap problem occurs because you are not using the y value in your DrawText Method. If you replace it with
it should look proper