Reputation: 5721
I would like to display a link in my AlertDialog, but after multiple attempts it still displays it as plain text.
I have tried the suggestions in the following links: How can I get clickable hyperlinks in AlertDialog from a string resource?
Here is my current state:
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();
}
});
Upvotes: 0
Views: 171
Reputation: 648
HyperLinks work only in HTML text. So you have to:
msg.setText(Html.fromHtml("BradcodeScanner app must be installed on your phone</br><a href=\"" + s + "\">click here</a>");
Upvotes: 1
Reputation: 1398
do you mean something like this?
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);
}
}
});
Upvotes: 0