Khá dễ dàng với lớp học TextView
tùy chỉnh. Hãy xem Canvas guide từ tài liệu để biết thêm thông tin về điều này. Lưu ý các ý kiến nơi bạn có thể thay đổi màu sắc/width:
public class ObliqueStrikeTextView extends TextView
{
private int dividerColor;
private Paint paint;
public ObliqueStrikeTextView(Context context)
{
super(context);
init(context);
}
public ObliqueStrikeTextView(Context context, AttributeSet attrs)
{
super(context, attrs);
init(context);
}
public ObliqueStrikeTextView(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
init(context);
}
private void init(Context context)
{
Resources resources = context.getResources();
//replace with your color
dividerColor = resources.getColor(R.color.black);
paint = new Paint();
paint.setColor(dividerColor);
//replace with your desired width
paint.setStrokeWidth(resources.getDimension(R.dimen.vertical_divider_width));
}
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
canvas.drawLine(0, getHeight(), getWidth(), 0, paint);
}
}
Bạn có thể sử dụng nó trong một file layout bằng cách tuyển đầy đủ quan điểm với gói của bạn, như thế này:
<your.package.name.ObliqueStrikeTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1234567890"
android:textSize="20sp"/>
Dưới đây là kết quả cuối cùng :
Xin chào đọc http://stackoverflow.com/questions/3881553/is-there-an-easy-way-to-strike-through-text-in-an-app-widget – iNan
Tôi đã thấy bài đăng đó, nhưng tôi cần nó một cách độc đáo. Tôi đã thử sử dụng 9patch trước đây, nhưng kết quả trông xấu xí. – Warlock