Html.fromHtml(<font color="red" size="24">你好</font>" )
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"android:paddingBottom="@dimen/activity_vertical_margin"android:gravity="center"android:orientation="vertical"tools:context=".MainActivity"><TextViewandroid:id="@+id/html_text"android:gravity="center"android:layout_width="wrap_content"android:layout_height="wrap_content" /><TextViewandroid:id="@+id/html_text2"android:gravity="center"android:layout_width="wrap_content"android:layout_height="wrap_content" /><TextViewandroid:id="@+id/html_text3"android:gravity="center"android:layout_width="wrap_content"android:layout_height="wrap_content" /></LinearLayout>然后Activity 的onCreate()方法
@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);textView = (TextView) findViewById(R.id.html_text);textView2 = (TextView) findViewById(R.id.html_text2);textView3 = (TextView) findViewById(R.id.html_text3);names = new ArrayList<>();counts = new ArrayList<>();message = new ArrayList<>();names.add("奥特曼");names.add("白雪公主与七个小矮人");names.add("沃德天·沃纳陌帅·帅德·布耀布耀德 ");counts.add(1);counts.add(123);counts.add(9090909);for (int i = 0; i < 3; i++) {message.add("<font color="red" size="20">"+names.get(i)+"</font>"+"向您发来"+"<font color="blue" size="30">"+counts.get(i)+"</font>"+"条信息");}textView.setText(Html.fromHtml(message.get(0)));textView2.setText(Html.fromHtml(message.get(1)));textView3.setText(Html.fromHtml(message.get(2)));}看下效果图,是不是很简单,只要简单的会html 就可实现这种效果
以上内容是小编给大家分享的Android TextView显示html样式的文字,希望本文分享能够帮助到大家。