What I am trying to accomplish is to have clickable hyperlinks in the message text displayed by an AlertDialog
. While the AlertDialog
implementation happily underlines and colors any hyperlinks (defined using <a href="...">
in the string resource passed to Builder.setMessage
) supplied the links do not become clickable.
The code I am currently using looks like this:
new AlertDialog.Builder(MainActivity.this).setTitle(
R.string.Title_About).setMessage(
getResources().getText(R.string.about))
.setPositiveButton(android.R.string.ok, null)
.setIcon(R.drawable.icon).show();
I'd like to avoid using a WebView
to just display a text snippet.
Actually, if you want to simply use a string without dealing with all the views, the fastest way is to find message textview and linkify it:
I combined some of the options discussed above to come up with this function that works for me. pass the result to dialog builder's SetView() method.
If you are using a
DialogFragment
, this solution should help.Instead of ...
... I now use:
I didn't really like the currently most popular answer because it significantly changes the formatting of the message in the dialog.
Here's a solution that will linkify your dialog text without otherwise changing the text styling:
If you are only showing some text and URL[s] in your dialog perhaps the solution is simpler
As shown here http://picasaweb.google.com/lh/photo/up29wTQeK_zuz-LLvre9wQ?feat=directlink