Did a bit of searching. I can see a way to add a shadow layer in a TextView, but I only want to obscure the range of text. I basically do an EditText where the user will be able to change the text selection style. One of these styles is the shadow with the color of choice. There are gaps for color, size, font, etc., but I can not find something for the shadows.
Basically, I want to do something like: (Note code from Mono Droid, but Java answer will be useful too)
var N = new ShadowSpan(color,dx,dy,radius);
int S = txEdit.SelectionStart;
int E = txEdit.SelectionEnd;
Str = new SpannableString(txEdit.TextFormatted);
Str.SetSpan(N,S,E, SpanTypes.InclusiveInclusive);
txEdit.SetText(Str, TextView.BufferType.Spannable);
txEdit.SetSelection(S,E);
Any help or suggestion is appreciated. I am wondering if I need to figure out how to get my own implementation of ShadowSpan from android.text.style.CharacterStyle (maybe override updateDrawState () on setShadowLayer with a TextPaint object?) Or maybe I just missed the simple answer? I cannot be the only one who wanted to do this, so I thought I would ask to go too far to try something ordinary.
- EDIT -
I tried to create my own ShadowSpan and it seems to work. I still leave the floor open if anyone has a better solution. Something seems to already exist, but I think I did not have to do too much.
Here is what I have in Mono for Android
public class ShadowSpan : Android.Text.Style.CharacterStyle
{
public float Dx;
public float Dy;
public float Radius;
public Android.Graphics.Color Color;
public ShadowSpan(float radius, float dx, float dy, Android.Graphics.Color color)
{
Radius = radius; Dx = dx; Dy = dy; Color = color;
}
public override void UpdateDrawState (TextPaint tp)
{
tp.SetShadowLayer(Radius, Dx, Dy, Color);
}
}
Used like that
void HandleClick (object sender, EventArgs e)
{
var N = new ShadowSpan(1,1,1,Android.Graphics.Color.Red);
int S = txEdit.SelectionStart;
int E = txEdit.SelectionEnd;
Str = new SpannableString(txEdit.TextFormatted);
Str.SetSpan(N,S,E, SpanTypes.InclusiveInclusive);
txEdit.SetText(Str, TextView.BufferType.Spannable);
txEdit.SetSelection(S,E);
}