简体   繁体   中英

Android HtmlCompat.fromHtml <del> tag is not working

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 = ""
    }
}

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM