简体   繁体   中英

How to show HTML text in TextView?

how to show this html code in TextView. without any minimum API requirement

HTML CODE IS BELOW:

<h2>Hey !</h2>
<blockquote>
<h2>Hey !</h2>
<blockquote>
  <p>
    <span style="color: #0000ff;">
      hello world 
      <em>
        <strong>
          is a virtual world.
        </strong>
      </em>
    </span>
    😂
  </p>
</blockquote>

Here is Solution.

package com.andro.coundowntimer;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.text.HtmlCompat;

import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    String htmlCode= "<h2>Hey !</h2>\n" +
                "<blockquote>\n" +
            "<p><span style=\"color: #0000ff;\">hello world <em><strong>is a virtual world.</strong></em></span>\uD83D\uDE02</p>\n" +
            "</blockquote>";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        TextView textView=findViewById(R.id.textView);
        textView.setText(HtmlCompat.fromHtml(htmlCode,0)); 
    }
}

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