1、布局文件
<TextView
android:id="@+id/tv_red"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
android:text="Hello World!"/>
2、代码
TextView tv_red;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv_red = (TextView) findViewById(R.id.tv_red);
Spanned textSpan1 = Html.fromHtml("你好,我是<font color=\"#ff0000\">红色</font>文字");
tv_red.setText(textSpan1);
}
3、效果图