1. 将要处理的文字写到一个资源文件,如string.xml(使用html用法格式化)
<resources>
<string name="hello"><u>phone:0123456</u></string>
</resources>
2. 当文字中出现URL、E-mail、电话号码等的时候,可以将TextView的android:autoLink属性设置为相应的的值,
如果是所有的类型都出来就是android:autoLink="all",当然也可以在java代码里 做,textView01.setAutoLinkMask(Linkify.ALL);
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:autoLink="all"
android:text="@string/link_text_auto" />
3. 用Html类的fromHtml()方法格式化要放到TextView里的文字 ,与第1种一样,只是是用代码动态设置
如果是代码里: 1、使用Html.fromHtml()
TextView textView = (TextView)findViewById(R.id.tv_test);
textView.setText(Html.fromHtml("<u>"+"0123456"+"</u>"));
2、使用TextView的Paint的属性
tvTest.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
tvTest.getPaint().setAntiAlias(true);//抗锯齿
3、使用SpannableString类
SpannableString content = new SpannableString(str);
content.setSpan(new UnderLineSpan, 0, str.length(), 0);