Search code examples
androidtextviewtext-size

personalize strikeThrough Textview


I use this to have stike through a textView

textView.setPaintFlags(textView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

but now I wanna personalize the color and rotate it 45° to fit the diagonal of the content.

What I tied:

I though about extending the textview widget and override onDraw method .. but I'm very beginner at designing ...

so any help how to draw the red(color) rotated line on the textView ?


Solution

  • adding to Mayani's response

    @Override
    protected void onDraw(Canvas canvas) {
        Paint paint = new Paint();
        paint.setColor(strikeThroughColor);
        paint.setStyle(Paint.Style.FILL);
        paint.setFakeBoldText(true);
        paint.setStrikeThruText(true);
        paint.setStrokeWidth(strikeThroughWidth);
        paint.setFlags(Paint.ANTI_ALIAS_FLAG);
        super.onDraw(canvas);
        float width = getWidth();
        float height = getHeight();
        canvas.drawLine(width / 10, height / 10, (width - width / 10), (height - height / 10), paint);
    }