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"); } }
textview添加超链接
最新推荐文章于 2021-05-26 16:55:21 发布