Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android HtmlCompat.fromHtml <del> tag is not working

Tags:

android

I have this kind of price html from server

<del><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&#8377;</span>12,000.00</span></del> <ins><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&#8377;</span>3,999.00</span></ins>

I am using HTMLCompact to render it in textview

HtmlCompat.fromHtml(description, HtmlCompat.FROM_HTML_MODE_COMPACT)

But discount text is not StrikeThrough. Del tag is completely being ingnored.

Code Implementation as requested

<TextView
   android:id="@+id/course_name"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_marginTop="16dp"
   android:fontFamily="@font/open_sans_semi_bold"
   app:renderHtmlText="@{viewModel.product.priceHtml}"
   android:textSize="18sp"  />


//Binding Adapter
@BindingAdapter("renderHtmlText")
fun bindRenderHtmlText(view: TextView, description: String?) {
    if (description != null) {
        view.text = HtmlCompat.fromHtml(description, HtmlCompat.FROM_HTML_MODE_COMPACT)
    } else {
        view.text = ""
    }
}
like image 380
Abhishek Singh Avatar asked Nov 06 '22 02:11

Abhishek Singh


1 Answers

Based on the logic of handleEndTag from Android framework source, outer del tag might be ignored by inner span tag.

The suggestion solution is add an inline style style="text-decoration: line-through; for compatibility like below.

<del>
    <span class="woocommerce-Price-amount amount" style="text-decoration: line-through;">
        <span class="woocommerce-Price-currencySymbol">&#8377;</span>12,000.00
    </span>
</del>
<ins><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&#8377;</span>3,999.00</span>

Or ajdust your html page structure to make del tag inside span tag.

<span class="woocommerce-Price-amount amount">
        <span class="woocommerce-Price-currencySymbol"><del>&#8377;</del></span><del>12,000.00</del>
</span>
<ins><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&#8377;</span>3,999.00</span>
</ins>
like image 88
alijandro Avatar answered Nov 23 '22 05:11

alijandro