原文地址:http://www.cnblogs.com/sunzn/p/3406013.html
通过如下这种方式给 TextView 添加的链接支持链接样式、点击事件、href 样式,代码如下:
package cn.sunzn.tlink; import android.app.Activity; import android.os.Bundle; import android.text.Html; import android.text.Spanned; import android.text.method.LinkMovementMethod; import android.view.Menu; import android.widget.TextView; public class MainActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView tv_sunzn = (TextView) findViewById(R.id.tv_sunzn); tv_sunzn.setMovementMethod(LinkMovementMethod.getInstance()); Spanned text = Html.fromHtml("博客园主页:<a href=\"http://www.cnblogs.com/kabu/">kabu</a>"); tv_sunzn.setText(text); } public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } }
时间: 2024-11-05 20:43:10