【问题标题】:Set hyperlink inside TextView in C# Android App在 C# Android App 中的 TextView 内设置超链接
【发布时间】:2016-07-31 17:18:52
【问题描述】:

我是初学者。我想像这样向 TextView 添加超链接: some_text [超链接] some_text.

<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" />

【问题讨论】:

标签: c# android xamarin


【解决方案1】:

您可以通过编程方式执行此操作。从 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;

【讨论】:

  • 现在已弃用!
  • 现在您必须在 FromHtml 方法中添加 FromHtmlOptions 枚举,以免被弃用,例如: textView.TextFormatted = Html.FromHtml("请阅读我们的 " + "xamarin.com\ ">规则和条件 " + "在使用应用之前。", FromHtmlOptions.ModeLegacy);
猜你喜欢
  • 1970-01-01
  • 2017-10-19
  • 2016-12-13
  • 2015-08-30
  • 2012-03-06
  • 2020-09-13
  • 1970-01-01
  • 1970-01-01
  • 2015-06-29
相关资源
最近更新 更多