在Android中创build删除线文本?

我可以在Android中创build删除线文本,我的意思是在TextView标签中添加一个特殊的值,可以使这成为可能?

 <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"/> 

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); 

对于绘制文本,有几个标志用于处理粗体,斜体和删除线。 所以要启用删除线,您需要翻转与此标志对应的位。 最简单的方法是在当前标志上使用一个按位或一个常量,而对应于只有删除线标志启用的一组标志的常量。

尝试这个 :

 richTextView = (TextView)findViewById(R.id.rich_text); // this is the text we'll be operating on SpannableString text = new SpannableString("Lorem ipsum dolor sit amet"); text.setSpan(new ForegroundColorSpan(Color.RED), 0, 5, 0); // make "ipsum" (characters 6 to 11) one and a half time bigger than the textbox text.setSpan(new RelativeSizeSpan(1.5f), 6, 11, 0); // make "dolor" (characters 12 to 17) display a toast message when touched final Context context = this; ClickableSpan clickableSpan = new ClickableSpan() { @Override public void onClick(View view) { Toast.makeText(context, "dolor", Toast.LENGTH_LONG).show(); } }; text.setSpan(clickableSpan, 12, 17, 0); // make "sit" (characters 18 to 21) struck through text.setSpan(new StrikethroughSpan(), 18, 21, 0); // make "amet" (characters 22 to 26) twice as big, green and a link to this site. // it's important to set the color after the URLSpan or the standard // link color will override it. text.setSpan(new RelativeSizeSpan(2f), 22, 26, 0); text.setSpan(new URLSpan("http://www.djsad.com"), 22, 26, 0); text.setSpan(new ForegroundColorSpan(Color.GREEN), 22, 26, 0); // make our ClickableSpans and URLSpans work richTextView.setMovementMethod(LinkMovementMethod.getInstance()); // shove our styled text into the TextView richTextView.setText(text, BufferType.SPANNABLE); 

我只是复制我的答案 。 希望它能帮助别人如果你有一个单词,我们可以使用drawable。 以下是例子:

 <item android:state_pressed="false"><shape android:shape="line"> <stroke android:width="2dp" android:color="#ffffff" /> </shape> </item> 

如果你有多行,你可以使用下面的代码:

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

如果你使用string,这真的很容易:

 <string name="line"> Not crossed <strike> crossed </strike> </string> 

然后只是:

 <TextView ... android:text="@string/line" />