How to make shadow range of strings in Android?

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); // no such thing?
        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);
    }
+3
source
3

, , CharacterStyle. , Google API Span. , . , , - - . , .

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);
    }
}
+7

, , Java, .

private static class ShadowStyleSpan extends ClickableSpan {
    private int radius;
    private int dx;
    private int dy;
    private int color;

    public ShadowStyleSpan(int radius, int dx, int dy, int color) {
        super();
        this.radius = radius;
        this.dx = dx;
        this.dy = dy;
        this.color = color;
    }

    @Override
    public void updateDrawState(TextPaint ds) {
        super.updateDrawState(ds);
        ds.setShadowLayer(radius, dx, dy, color);
    }
}
+4

, android: shadowColor, android: shadowDx, android: shadowDy, android: shadowRadius; setShadowLayer().

, ( )

.

0

All Articles