WEB开发网
开发学院手机开发Android 开发 Android TextView实现超链接 阅读

Android TextView实现超链接

 2010-02-03 19:13:00 来源:WEB开发网   
核心提示: TextView t3 = (TextView) findViewById(R.id.text3); t3.setText( Html.fromHtml( "text3: Text with a " + "http://www.google.com\">link

   TextView t3 = (TextView) findViewById(R.id.text3);
     t3.setText(
       Html.fromHtml(
         "text3: Text with a " +
         "http://www.google.com\">link> " +
         "created in the Java source code using HTML."));
     t3.setMovementMethod(LinkMovementMethod.getInstance());

   // text4 illustrates constructing a styled string containing a
     // link without using HTML at all. Again, for a fixed string
     // you should probably be using a string resource, not a
     // hardcoded value.

   SpannableString ss = new SpannableString(
       "text4: Click here to dial the phone.");

   ss.setSpan(new StyleSpan(Typeface.BOLD), 0, 6,
          Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
     ss.setSpan(new URLSpan("tel:4155551212"), 13, 17,
          Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

   TextView t4 = (TextView) findViewById(R.id.text4);
     t4.setText(ss);
     t4.setMovementMethod(LinkMovementMethod.getInstance());
   }
}

上一页  1 2 

Tags:Android TextView 实现

编辑录入:coldstar [复制链接] [打 印]
赞助商链接