2016-07-31 110 views
0

我是初學者。我想添加像這樣的超文本鏈接到TextView: some_text [hyperlink] some_text。在C#中的TextView中設置超鏈接Android應用程序

<TextView 
    android:text="Please read our *rules and conditions* before using app." 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/textView" 
    android:textColor="#000000" 
    android:autoLink="web" /> 
+1

[URL中的TextView Android的活動鏈接(可能的重複http://stackoverflow.com/questions/6910703/android-active-link-of -url-in-textview) – SushiHangover

+0

我想要的文字與實際網址不同 – Aagha

回答

2

您可以通過編程來實現。從TextView中刪除autoLink屬性。

<TextView 
    android:id="@+id/textView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 

在你的Activity類,

TextView textView = FindViewById<TextView>(Resource.Id.textView); 
textView.TextFormatted = Html.FromHtml("Please read our " + 
       "<a href=\"http://www.xamarin.com\">Rules and Conditions</a> " + 
       "before using app."); 

textView.MovementMethod = LinkMovementMethod.Instance; 
+0

非常感謝。它效果很好。 – Aagha

相關問題