我想在警报对话框中添加我的(Facebook页面)链接,如下所示:
public void visitFAcebook(){
new AlertDialog.Builder(this)
.setTitle("Find Us On Facebook")
.setMessage("www.facebook.com/mypage")
.show();
}
我可以将消息转换为可点击的链接吗?
对代码进行以下更改。您可以更改颜色和字体,如下所示。
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());
}
安卓仅支持以下标签
<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>