當textview設定 android:autolink="all"時,
textview裡的相關內容會出現link,請問要如何取得link的這段字串?

解决方案 »

  1.   

    看下textView接口吧,下份android 自带文档,学起来也方便许多
      

  2.   

    已經解決了。分享一下code,方法不是很完美,有問題請多指教。TextView tv = (TextView)findViewById(R.id.textView1);

    String s = "這是一段測試的string www.google.com test";
    tv.setText(s);
    URLSpan[] texts = tv.getUrls();
    for(URLSpan text:texts){
    Uri uri = Uri.parse(text.getURL());
    String s01 = uri.toString();
    if(s01.startsWith("http://")){
        String s02 = s01.substring(7, s01.length());
        Toast.makeText(this, s02, Toast.LENGTH_LONG).show();
    }else if(s01.startsWith("tel:")){
        String s02 = s01.substring(4, s01.length());
        Toast.makeText(this, s02, Toast.LENGTH_LONG).show();
    }else if(s01.startsWith("mailto:")){
        String s02 = s01.substring(7, s01.length());
        Toast.makeText(this, s02, Toast.LENGTH_LONG).show();
    }
    }以上不會抓到map的連結字串,因為我沒有需要用到,所以偷懶了。