Updated 22 April 2017
There are many scenarios in which we need to show a Strike-through text to an android user like Old prices, old offers, etc. But android doesn’t give any such option via XML file.
So, How we can set a text in TextView to show a Strike-through text via DataBinding?
1 2 3 4 5 6 7 8 9 |
<TextView android:id="@+id/list_price" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@{products.formatlistPrice}" android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textColor="@color/primary_color" tools:text="@string/price"/> |
1 2 3 4 5 |
public SpannableString getFormatlistPrice() { SpannableString formatListPrice = new SpannableString(this.formatlistPrice); formatListPrice.setSpan(new StrikethroughSpan(), 0, this.formatlistPrice.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); return formatListPrice; } |
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.