textview添加超链接

来源:互联网 发布:mysql 查找所有子部门 编辑:程序博客网 时间:2024/05/16 07:07
import android.app.Activity;import android.os.Bundle;import android.text.Html;import android.text.method.LinkMovementMethod;import android.text.util.Linkify;import android.widget.LinearLayout;import android.widget.TextView;/** * Created by  on 2016/7/15. */public class Main extends Activity {    public void onCreate(Bundle b)    {        super.onCreate(b);        LinearLayout layer=new LinearLayout(this);        TextView top=new TextView(this);        TextView bottom=new TextView(this);        bottom.setPadding(0,100,0,0);        layer.setOrientation(LinearLayout.VERTICAL);        layer.addView(top);        layer.addView(bottom);        setContentView(layer);        top.setMovementMethod(LinkMovementMethod.getInstance());        CharSequence str= Html.fromHtml(" 百度一下<a href=\"http://www.baidu.com\">你就知道</a>");        top.setText(str);        bottom.setMovementMethod(LinkMovementMethod.getInstance());        bottom.setAutoLinkMask(Linkify.ALL);        bottom.setText("百度一下www.baidu.com");    }}
0 0