For that, follow the below steps:
- Create a custom TextView by extending
View
class
- Declare this custom textview inside XML layout same like we do for TextView, Button widgets.
For example:
class CustomTextView extends View {
private int mColor;
private int mRotationAngle, mRotationW, mRotationH;
private String mText;
public CustomTextView(Context context) {
super(context);
// set default parameters
mColor = Color.WHITE;
mRotationAngle = 0;
}
public void SetColor(int newcolor) {
mColor = newcolor;
this.invalidate();
}
public void SetRotation(int newangle, int neww, int newh) {
mRotationAngle = newangle;
mRotationW = neww;
mRotationH = newh;
this.invalidate();
}
public void SetText(String newtext) {
mText = newtext;
this.invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
canvas.rotate(mRotationAngle,mRotationW,mRotationH);
canvas.drawText(mText, 0, 0, paint);
super.onDraw(canvas);
}
}
Update:
Check for Specifying “strikethrough” on a section of TextView text