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.
This is my solution. It creates a normal link without html tags involved and without any URL visible. It also keeps the design intact.
This should make
<a href>
tags to get highlighted as well. Please note that i have just added a few lines to emmby's code. so credit to himI do this by specifying the alert box in an XML resource and loading that. See for example the about.xml (see the ABOUT_URL id) that gets instantiated near the end of ChandlerQE.java. The relevant parts from the java code:
All the above answer will not remove html tag like , etc if the given string contains, I tried to remove all the tags, and this is work fine for me
and the custom_dialog would be like;
The above code will remove all the html tag and shows Example as Click able URL all others in the specified html formatting text.
I've checked many questions and answers, but it doesn't work. I did it myself. This is the code snippet on MainActivity.java.
Put this tag on res\values\String.xml
I was not really satisfied with the current answers. There are two things that are important when you want clickable hyperlinks in href style withing an AlertDialog:
setMessage(…)
, as only Views allow clickable HTML contentsetMovementMethod(…)
)Here is a working minimal example:
strings.xml
MyActivity.java