【问题标题】:Android textview with clickable phone number [closed]带有可点击电话号码的Android textview [关闭]
【发布时间】:2013-01-23 15:38:03
【问题描述】:

我有一个 textview 显示 电话:0900-1111,传真:0900-2222

有没有办法让手机可以点击但传真不能点击。

使用

Phone: <a href="tel:09001111">0900-1111</a>, Fax: 0900-2222

将自动链接设置为手机,两者都是可点击的!

【问题讨论】:

  • 为什么这甚至被关闭和投票这么多?这是一个很好的问题,有一个很好的答案。
  • 1 年内查看 1853 次。我认为这不是一个坏问题
  • 我觉得这是个好问题?

标签: android hyperlink textview tel


【解决方案1】:

您检查过 API 演示吗?

他们在 Views/Text/Linkify 下有一个示例。

该类位于 com.example.android.apis.text.Link.java

例如,其中一个 textView 使用的字符串是:

<string name="link_text_manual"><b>text2: Explicit links using &lt;a&gt; markup.</b>
  This has markup for a <a href="http://www.google.com">link</a> specified
  via an &lt;a&gt; tag.  Use a \"tel:\" URL
  to <a href="tel:4155551212">dial a phone number</a>.
</string>

文本视图是:

  <TextView android:id="@+id/text2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingTop="8dp"
            android:paddingBottom="8dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="@string/link_text_manual"
            />

【讨论】:

  • 我使用它,但我有 2 个链接,而不是只有一个通过锚标签指定的链接...
  • 我不明白。您能否展示一下您想要拥有什么,以及您尝试过做什么?那里的示例有很多不同的链接,都是可定制的,可以打开/关闭。
  • 电话:0900-1111,传真:0900-2222 ...我希望传真号码不可点击。我尝试了使用或不使用 href=tel,但它们始终都是可点击的。
  • 您是否尝试过禁用自动链接,正如我所写的那样?你试过样品吗?请尝试,然后更新您的问题,因为它不包含表明它不起作用的代码示例。
  • 谢谢...确实,我必须删除 autoLink 才能让 href 按字符串中的定义工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-24
相关资源
最近更新 更多