1

I am writing text on image and saving that image to SD Card. I want the image text to appear like this enter image description here. I have tried using a custom TextView and applied the below logic in onDraw() method

 package com.test;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.widget.TextView;

public class BlackStrokeTextView extends TextView {

    private TextPaint mStrokePaint;

    public BlackStrokeTextView(Context context) {
        super(context);
        init(null);
    }

    public BlackStrokeTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(attrs);
    }

    public BlackStrokeTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(attrs);
    }

    public void init(AttributeSet attrs) {
         // lazy load
        if (mStrokePaint == null) {
            mStrokePaint = new TextPaint();
        }

     // copy
        mStrokePaint.setTextSize(getTextSize());
        mStrokePaint.setTypeface(getTypeface());
        mStrokePaint.setFlags(getPaintFlags());

        mStrokePaint.setTypeface(Typeface.createFromAsset(getResources().getAssets(), "fonts/impact.ttf"));

        // custom
        mStrokePaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mStrokePaint.setColor(Color.BLACK);
        mStrokePaint.setStrokeWidth(8);

        setTypeface(Typeface.createFromAsset(getResources().getAssets(), "fonts/impact.ttf"));

    }

    @Override
    protected void onDraw(Canvas canvas) {

        String text = getText().toString();
        float x = (getWidth() - mStrokePaint.measureText(text)) / 2;
        float y = getBaseline();
        canvas.drawText(text, x, y, mStrokePaint);
        super.onDraw(canvas);
    }

}
KK_07k11A0585
  • 2,381
  • 3
  • 26
  • 33

1 Answers1

1

You can use the below tags for your TextView

 android:shadowColor 
 android:shadowDx
 android:shadowDy 
 android:shadowRadius

see this so How to make text glow?

Community
  • 1
  • 1
Spring Breaker
  • 8,233
  • 3
  • 36
  • 60
  • Hi @Spring Breaker Many Thanks! for yor quick reply. I have applied that logic it is giving the shadow but it was very light one. Not as dark as it was in the above image. This was my output when i use the shadow Logic https://pbs.twimg.com/media/Bnqqk03IYAAGA1U.png – KK_07k11A0585 May 15 '14 at 09:30
  • 1
    @KK_07k11A0585: You can play with those properties by changing its values to get your desired effect. – Spring Breaker May 15 '14 at 09:37
  • Thanks i will check. My only problem is i want the shadow to be darker. I i use any other color then it is coming darker . But i when i use black color the shadow is not as darker as it is expected to be – KK_07k11A0585 May 15 '14 at 09:41