Reputation: 1007
want to add textview which will have black text color and Strike with different color
for strile using
txtview.setPaintFlags(txtview.getPaintFlags()|Paint.STRIKE_THRU_TEXT_FLAG);
Upvotes: 1
Views: 803
Reputation: 3673
You can do this in three ways, by either setting foreground in TextView
, or setting PaintFlag
or declaring string as <strike>your_string</strike>
in strings.xml
. For example,
Through PaintFlag
This is simplest method you just have to set strikethrough flag on your TextView as,
yourTextView.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
it will strike through your TextView.
Through foreground drawable
You can also strike through your TextView by setting a background as,
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<shape android:shape="line">
<stroke android:width="1dp" android:color="@android:color/holo_red_dark"/>
</shape>
</item>
</selector>
Now, you just have to set above drawable in your TextView as background.
Through strings.xml
In this method, you have to declare your string in strings.xml as strike through as,
<string name="strike_line"> <strike>This line is strike throughed</strike></string>
Note
But I recommend you to strike through your TextView by setting foreground drawable. Because through drawable you can easily set your strike through line color(as like I setted as red color in above example) or size or any other style property. While in other two methods default textcolor is strike through color.
Upvotes: 2