public class Link extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.link); // text1 shows the android:autoLink property, which // automatically linkifies things like URLs and phone numbers // found in the text. No java code is needed to make this // work. // text2 has links specified by putting tags in the string // resource. By default these links will appear but not // respond to user input. To make them active, you need to // call setMovementMethod() on the TextView object. TextView t2 = (TextView) findViewById(R.id.text2); t2.setMovementMethod(LinkMovementMethod.getInstance()); // text3 shows creating text with links from HTML in the Java // code, rather than from a string resource. Note that for a // fixed string, using a (localizable) resource as shown above // is usually a better way to go; this example is intended to // illustrate how you might display text that came from a // dynamic source (eg, the network). 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. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android应用程序注冊广播接收器(registerR
  2. drawable属性
  3. 【Android游戏开发十六】Android Gesture
  4. android使用Intent实现页面跳转--startActi
  5. android:ellipsize实现跑马灯效果总结
  6. Android做按住显密码的View
  7. Android之UI学习篇三:TextVeiw单击文字链
  8. 获取Android System 写入权限
  9. Android培训班(8)
  10. Android SDK更新失败的解决方案(原创)