Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
494 views
in Technique[技术] by (71.8m points)

android - creating a strikethrough text?

Can I create a strikethrough text in Android, I mean adding a special value in the TextView tag that can make this possible?

<TextView
    android:id="@+id/title" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:textColor="#040404"
    android:typeface="sans" 
    android:textSize="12dip"
    android:textStyle="bold"/>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Paint.STRIKE_THRU_TEXT_FLAG

TextView someTextView = (TextView) findViewById(R.id.some_text_view);
someTextView.setText(someString);
someTextView.setPaintFlags(someTextView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);

For painting text, there are several bit flags for doing things like bold, italics, and yes strikethrough. So to enable the strikethrough, you need to flip the bit that corresponds to this flag. The easiest way to do this is to use a bitwise-or on the current flags and a constant that corresponds to a set of flags with only the strikethrough flag enabled.

Edit from Comment by Ε Г И ? И О :

For any one wanting to remove this flag, this is how:

someTextView.setPaintFlags(someTextView.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...