我阅读了示例代码并尝试了以下内容,但它不起作用。该文字似乎不是一个超链接。请帮忙:(
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 ....“点击这里”成为常规文本
但是我想将randomString放在textview中。
答案 0 :(得分:3)
您的网址周围缺少引号。尝试:
Html.fromHtml("<a href='https://play.google.com/store/apps/details?id=com.xxxxxxxxx'>Click Here</a>")
请注意网址周围的单引号。
答案 1 :(得分:0)
您需要使用HTML格式的所有内容
像这样Html.fromHtml(
"<b>Hello</b><br>" +
"<a href='https://play.google.com/store/apps/details?id=com.xxxxxxxxx'>Click Here</a>"
)
答案 2 :(得分:0)
AlertDialog.Builder builder1 = new AlertDialog.Builder(youractivity.this);
builder1.setMessage(Html.fromHtml("your message,<a href=\"http://www.google.com\">link</a>"));
builder1.setCancelable(false);
builder1.setPositiveButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog Alert1 = builder1.create();
Alert1 .show();
((TextView)Alert1.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());