Android - AlertDialog 中的超链接
Android - Hyperlink in AlertDialog
我想在我的 AlertDialog 中显示 link,但多次尝试后它仍然显示为纯文本。
我尝试了以下link中的建议:
How can I get clickable hyperlinks in AlertDialog from a string resource?
Android link in dialog
这是我目前的状态:
final TextView msg = new TextView(context);
final SpannableString s = new SpannableString("https://play.google.com/store/apps/details?id=com.google.zxing.client.android");
Linkify.addLinks(s, Linkify.WEB_URLS);
msg.setText("BradcodeScanner app must be installed on your phone\n" +
"click on the link below.\n\n" +s);
msg.setMovementMethod(LinkMovementMethod.getInstance());
info_img = (ImageView) findViewById(R.id.qr_info);
info_img.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
new AlertDialog.Builder(context)
.setTitle("QR Location Scan")
.setView(msg)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
})
.setIcon(android.R.drawable.ic_dialog_info)
.show();
}
});
你的意思是这样的吗?
mTvContent.setPaintFlags(mTvContent.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
mTvContent.setTextColor(ContextCompat.getColor(this, R.color.aviary_accent_blue));
mTvContent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (link.contains("http://")) {
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse(link));
context.startActivity(i);
} else {
link = "http://" + link;
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse(link));
context.startActivity(i);
}
}
});
超链接仅在 HTML 文本中有效。所以你必须:
msg.setText(Html.fromHtml("BradcodeScanner app must be installed on your phone</br><a href=\"" + s + "\">click here</a>");
我想在我的 AlertDialog 中显示 link,但多次尝试后它仍然显示为纯文本。
我尝试了以下link中的建议: How can I get clickable hyperlinks in AlertDialog from a string resource?
Android link in dialog
这是我目前的状态:
final TextView msg = new TextView(context);
final SpannableString s = new SpannableString("https://play.google.com/store/apps/details?id=com.google.zxing.client.android");
Linkify.addLinks(s, Linkify.WEB_URLS);
msg.setText("BradcodeScanner app must be installed on your phone\n" +
"click on the link below.\n\n" +s);
msg.setMovementMethod(LinkMovementMethod.getInstance());
info_img = (ImageView) findViewById(R.id.qr_info);
info_img.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
new AlertDialog.Builder(context)
.setTitle("QR Location Scan")
.setView(msg)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
})
.setIcon(android.R.drawable.ic_dialog_info)
.show();
}
});
你的意思是这样的吗?
mTvContent.setPaintFlags(mTvContent.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
mTvContent.setTextColor(ContextCompat.getColor(this, R.color.aviary_accent_blue));
mTvContent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (link.contains("http://")) {
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse(link));
context.startActivity(i);
} else {
link = "http://" + link;
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse(link));
context.startActivity(i);
}
}
});
超链接仅在 HTML 文本中有效。所以你必须:
msg.setText(Html.fromHtml("BradcodeScanner app must be installed on your phone</br><a href=\"" + s + "\">click here</a>");