2012-06-30 26 views
-1

我從我的資源strings.xml中取出一個字符串並將該字符串放入TextView中。在文本視圖中添加一個鏈接並在導航器上打開此鏈接

在strings.xml中:

<string name="description">Hello please look into <a href="http://www.webtour.dk">www.webtour.dk</a></string> 

main.xml中:

<TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/description" 
       android:textSize="12dp" 
       android:textStyle="bold" /> 

我得到這個結果的好成績,www.webtour.dk作爲一個鏈接出現。但是當我點擊鏈接時,我什麼都沒有!沒有導航器啓動?

回答

2

只需使用Linkify自動尋找網站:

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:autoLink="web" 
    android:text="@string/description" 
    android:textSize="12dp" 
    android:textStyle="bold" /> 

然後把HTML從你的文字:

<string name="description">Hello please look into www.webtour.dk</string> 
相關問題