如何在Alert Dialog中建立像Facebook页面这样的网页链接?

时间:2017-11-07 03:39:20

标签: android facebook hyperlink dialog clickable

我想在警告对话框中添加我的(Facebook页面)链接,如下所示:

public void visitFAcebook(){
    new AlertDialog.Builder(this)
            .setTitle("Find Us On Facebook")
            .setMessage("www.facebook.com/mypage")

            .show();

}

我可以将邮件转换为可点击链接吗?

1 个答案:

答案 0 :(得分:0)

对您的代码进行以下更改。您可以更改颜色和字体,如下所示。

public void visitFacebook(){
        String fbLink = "<a href=\"http://www.facebook.com/mypage\">My Facebook Page</a>";
        String Txt = "Click to visit facebook: "+"<h1>"+"<font color=blue>"+ fbLink+"</font></h1>";
        Spanned fbString = Html.fromHtml(Txt);


        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Title");
        builder.setMessage(fbString);
        builder.setCancelable(true);
        AlertDialog alertDialog = builder.create();
        alertDialog.show();
        TextView msgTxt = (TextView) alertDialog.findViewById(android.R.id.message);
        msgTxt.setMovementMethod(LinkMovementMethod.getInstance());
    }

Android仅支持以下标记

<a href="...">
<b>
<big>
<blockquote>
<br>
<cite>
<dfn>
<div align="...">
<em>
<font size="..." color="..." face="...">
<h1>
<h2>
<h3>
<h4>
<h5>
<h6>
<i>
<img src="...">
<p>
<small>
<strike>
<strong>
<sub>
<sup>
<tt>
<u>