そのためには、以下の手順に従ってください。
- クラスを拡張してカスタムTextViewを作成する
View
- TextView、Buttonウィジェットの場合と同じように、XMLレイアウト内でこのカスタムtextviewを宣言します。
例えば:
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);
}
}
アップデート:
TextViewテキストのセクションで「取り消し線」を指定しているかどうかを確認します