【问题标题】:Convert string to Link将字符串转换为链接
【发布时间】:2018-09-14 05:48:07
【问题描述】:

我在我的应用程序中提供了“共享”选项。当用户单击它时,假设用户选择“与”WhatsApp 或 Twitter 共享,我将显示一个自定义消息模板,该模板默认显示在消息中,就在 WhatsApp 或 Twitter 启动时。我有一条消息和一个链接。我想让那个链接可以点击。现在消息和链接都以字符串形式出现。任何人都可以帮助我实现这一目标。

我会简化:

当前:“欢迎使用 Google https://google.com”

必填:“Welcome to Google”https://google.com(链接应显示为蓝色且可点击)

我的代码如下:

private void redirectUserToShareWith() {
    Intent referIntent = new Intent();
    referIntent.setAction(Intent.ACTION_SEND);
    String dynamicUrl = "https://google.com";
    String linkedText = String.format("<a href=\"%s\">link</a> ", dynamicUrl);
    referIntent.putExtra(Intent.EXTRA_TEXT, mCtx.getString(R.string.message_body) + Html.fromHtml(linkedText));
    referIntent.setType("text/plain");
    mCtx.startActivity(referIntent);
}

【问题讨论】:

  • 这不是文本视图。它只是一个字符串。我直接将字符串设置为消息。消息的一半是普通字符串,其余是链接。
  • 如果这不是文本视图,您在哪里显示此消息?
  • 我在一种模板中显示消息。我通过意图传递消息。

标签: android hyperlink


【解决方案1】:

检查一下,下面的代码对我有用

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT,
                "Hey check out my app at: https://play.google.com/store/apps/details?id=com.osmanaslanoglu.kizane");
sendIntent.setType("text/plain");
startActivity(sendIntent);

【讨论】:

    猜你喜欢
    • 2015-12-03
    • 1970-01-01
    • 1970-01-01
    • 2021-05-13
    • 1970-01-01
    • 2020-12-27
    • 1970-01-01
    • 2015-12-12
    • 2015-02-25
    相关资源
    最近更新 更多