TextView显示html

public class Main extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		TextView textView1 = (TextView) findViewById(R.id.textview1);
		TextView textView2 = (TextView) findViewById(R.id.textview2);

		String html = "<font color='red'>I love Android.</font><br>";
		html += "<font color='#0000FF' ><big><i>I love Android.</i></big></font><p>";
		html += "<font color='@"
				+ android.R.color.white
				+ "' ><tt><b><big><u>I love Android.</u></big><b></tt></font><p>";
		html += "<big><a href='http://51happyblog.com'>我的网站:51happyblog.com</a></big>";

		CharSequence charSequence = Html.fromHtml(html);

		textView1.setText(charSequence);

		//单击链接,调用浏览器显示网页
		textView1.setMovementMethod(LinkMovementMethod.getInstance());

		String text = "我的URL:http://51happyblog.com\n";
		text += "我的Email:abcd@126.com\n";
		text += "我的电话:+86 024-12345678";
		textView2.setText(text);
		textView2.setAutoLinkMask(Linkify.ALL);//设置网址、邮箱、电话等的自动链接
		textView2.setMovementMethod(LinkMovementMethod.getInstance());
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值