2014-09-11 47 views
2

所以我有一些文字一個TextView如下如何TextView中的部分鏈接到活動

一些文字....一些文字....一些文字....一些文字...一些文字....一些文字....一些文字....一些文字...... href.link ......其他一些文字.....其他一些文字。 .....其他一些文字.....其他一些文字....其他一些文字...

我只想讓文字的鏈接部分在點擊時啓動另一個活動。我試圖做到這一點在Xamarin,至今我也做了以下內容:

TextView1.SetText(Html.FromHtml("<span>some text...<a href='example://'></a>...some other text </span>" 

在我的目標活動:

[IntentFilter(new[] { Intent.ActionView }, 
    DataScheme = "example", 
Categories = new[] { Intent.CategoryDefault })] 

,我猜是equivlent到:

<intent-filter> 
<category android:name="android.intent.category.DEFAULT" /> 
<action android:name="android.intent.action.VIEW" /> 
<data android:scheme="example" /> 
</intent-filter> 

不知道在這裏設置什麼方案。

+0

最好保持2個textViews很近才達到你的目標 – 2014-09-11 11:34:20

+0

您可以使用HTML與Html.fromHtml() – zgc7009 2014-09-11 11:45:48

+0

入住此http格式://stackoverflow.com/questions/1697084鏈接可能有所幫助。 – Pankaj 2014-09-11 14:21:04

回答

1

我想通了。顯然,我必須把它添加到代碼(有問題),使其工作 -

TextView1.MovementMethod = LinkMovementMethod.Instance; 
0

這就是我在Xamarin中做類似的事情。我的佈局中有一個TextView,叫lblCreateNewAccount。在活動的OnCreate方法,我這樣做:

TextView lbl = this.FindViewById<TextView> (Resource.Id.lblCreateNewAccount); 
lbl.TextFormatted = Android.Text.Html.FromHtml ("<u>Create New Account</u>"); 
lbl.SetTextColor (Color.ParseColor ("#ffffff")); 
Typeface face = Typeface.CreateFromAsset (this.Assets, "fonts/OpenSansRegular.ttf"); 
lbl.SetTypeface (face, TypefaceStyle.Normal); 
lbl.Click += lblCreateNewAccount_Clicked; 

這裏是您簡化lblCreateNewAccount_Clicked方法:

void lblCreateNewAccount_Clicked (object sender, EventArgs e) 
{ 
    this.StartActivity (typeof(NewAccountActivity)); 
} 

基本概念是將TextView格式作爲href,然後實現Click事件導航到下一個活動。不知道這是不是最好,最優雅的方式,但它適用於我。在這種情況下,您將不得不使用三個TextView控件。

+0

謝謝。實際上,整個文本太長而不能保持一行。所以保留三個TextViews不會有幫助。就像鏈接出現在段落中間的某處 – benin101 2014-09-12 15:51:12

相關問題