0

我正試圖實現像這樣的圖像image twitter tweet。用戶使用哈希標籤和鏈接創建推文,並將Twitter應用轉換爲可點擊的鏈接。正常的TextView無法實現。我如何創建類似的東西?請提供技術細節。如何使用動態鏈接創建類似Twitter的提要帖子視圖?

+0

的可能的複製[我如何在TextView中可點擊的鏈接?](https://stackoverflow.com/questions/2734270/怎麼辦 - 我 - 讓鏈接-IN-A-TextView的,可點擊) –

回答

0

嘗試這個 用戶ClickableSpan實現這一這樣

 ClickableSpan clickableSpan = new ClickableSpan() { 
     @Override 
     public void onClick(View textView) { 
      Toast.makeText(context,"clicked", Toast.LENGTH_SHORT).show(); 

     } 
    }; 

     SpannableStringBuilder builder = new SpannableStringBuilder(); 

     SpannableString str1 = new SpannableString("click me"); 
     str1.setSpan(clickableSpan, 0, str1.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 
     str1.setSpan(new ForegroundColorSpan(Color.BLUE), 0, str1.length(), 0); 
     str1.setSpan(new UnderlineSpan(), 0, str1.length(), 0); 

     SpannableString str2 = new SpannableString("demo String 2 "); 
     builder.append(str2); 
     builder.append(str1); 

     Textview.setText(builder, TextView.BufferType.SPANNABLE); 
     Textview.setMovementMethod(LinkMovementMethod.getInstance()); 
相關問題