如何在Alertdialog上显示文本和可单击的URL链接? [英] How to have text and clickable URL link on Alertdialog?

查看:150
本文介绍了如何在Alertdialog上显示文本和可单击的URL链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了示例代码,并在下面尝试了一些方法,但是它不起作用.该文本似乎不是超链接.请帮助:(

I read sample codes and tried something below, but it doesn't work. The text didn't appear to be a hyperlink. Please help:(

String randomString = XXXX.getString();
        if(randomString .contains("XXXX"))
        {
            TextView tv  = new TextView(this);
            tv.setMovementMethod(LinkMovementMethod.getInstance());
            tv.setText(randomString +"/n"+Html.fromHtml("<a href=https://play.google.com/store/apps/details?id=com.xxxxxxxxx>Click Here</a>"));
            AlertDialog dialog = new AlertDialog.Builder(activity.this)
            .setView(tv)
            .setPositiveButton("OK!", new DialogInterface.OnClickListener()
            {

                public void onClick(DialogInterface dialog, int which)
                {

                }
            })
            .show();

        }

这项工作:

tv.setText(Html.fromHtml("<br><a href=https://play.google.com/store/apps/details?id=com.xxxxxxxxx>Click Here</a>"));

没有randomString+

我一经放入randomString + Html.fromHtml....单击此处"将成为常规文本

As soon as I put the randomString+Html.fromHtml.... The "Click Here" become a regular text

但是我也想将randomString放在textview内.

But I would like to put the randomString inside the textview as well.

推荐答案

您在URL周围缺少引号.试试:

You're missing quotes around your URL. Try:

Html.fromHtml("<a href='https://play.google.com/store/apps/details?id=com.xxxxxxxxx'>Click Here</a>")

请注意URL周围的单引号.

Note the single quotes around the URL.

这篇关于如何在Alertdialog上显示文本和可单击的URL链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆