【问题标题】:android:autoLink is not working in ButtonView in Android?android:autoLink 在 Android 的 ButtonView 中不起作用?
【发布时间】:2020-11-04 13:31:06
【问题描述】:

我在 ButtonView 中使用了自动链接,如下所示,

 <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/email"
            android:autoLink="email"
            />

如果我使用下面这样的字符串,我就可以发送电子邮件了,

<string name="mail"><a href = "abc@gmail.com">abc@gmail.com</a></string>

但是如果我喜欢下面的,不会发生,

<string name="mail"><a href = "abc@gmail.com">Send Mail</a></string>

这就是问题... 但点击按钮没有任何反应...... 当我为 textView 使用自动链接时效果很好.. 但是为什么不为 Button 工作???提前谢谢

【问题讨论】:

  • 请分享java代码
  • 我在下面回答...试试那个方法
  • 因为abc@gmail.com这不是一个有效的链接
  • @这只是参考...不是实际的电子邮件
  • 但该引用应该是有效的链接......不应该是电子邮件地址

标签: android xml android-button autolink


【解决方案1】:

Hai Sandhiya 你可以使用 Linkify 类来实现你的需求。试试那个

【讨论】:

    【解决方案2】:

    像下面这样解决了我的问题,

    mailRedirectButton.setAutoLinkMask(0);
    String content="<a href =mailto:abc@gmail.com>Send</a>";
            mailRedirectButton.setText(Html.fromHtml(content));
            mailRedirectButton.setMovementMethod(LinkMovementMethod.getInstance());
    

    参考这里https://stackoverflow.com/a/33709981/12273964

    感谢所有试图帮助我的人..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-19
      • 1970-01-01
      • 2016-07-19
      • 2018-06-18
      • 2017-11-08
      • 2021-08-31
      • 2016-02-20
      • 2015-05-25
      相关资源
      最近更新 更多