0

I have string xml formatted as follow:

<string name="dialog_message">My Super beautiful string<a href="https://mylink.com">Click me!</a>.\n\n\n\nVersion %1$s Build %2$s</string>

Then I have an AlertDialog like this:

        String message = context.getString(R.string.dialog_message, "My Version Name", "3");
        AlertDialog builder =
                new AlertDialog.Builder(context, R.style.AlertDialogCustom).setTitle(context.getResources().getString(R.string.app_name))
                        .setCancelable(false)
                        .setIcon(R.mipmap.ic_launcher_home)
                        .setMessage(message)
.create();
        builder.show();
        ((TextView)builder.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
        ((TextView)builder.findViewById(android.R.id.message)).setGravity(Gravity.CENTER_VERTICAL);

But it doesn't work (link not clickable)..it only work if I call .setMessage(R.string.dialog_message)

Why it doesn't work? I've tried also with .setView() method with custom TextView

Michele Lacorte
  • 4,922
  • 5
  • 29
  • 52
  • hi can you try this .. final SpannableString s = new SpannableString(context.getText(R.string.dialog_message)); https://stackoverflow.com/a/2000784 https://stackoverflow.com/a/12809761 – Madhav Anadkat Nov 08 '17 at 12:17
  • @MadhavAnadkat already tried not helped, not duplicate because it works only if I don't format string! – Michele Lacorte Nov 08 '17 at 12:20
  • have you tried this both lines ? final SpannableString s = new SpannableString(context.getText(R.string.dialog_message)); Linkify.addLinks(s, Linkify.WEB_URLS); – Madhav Anadkat Nov 08 '17 at 12:27
  • Yes... @MadhavAnadkat – Michele Lacorte Nov 08 '17 at 12:32
  • Okay.. let me tell you what workaround you can do for now. final WebView message = new WebView(this); message.loadData(getText(R.string.dialog_message).toString(), "text/html", "UTF-8"); change below lines. .setMessage(message) with .setView(message) also, when you do that, you also have to change the string line to. My Super beautiful string Click me!.\n\n\n\nVersion %1$s Build %2$s]]> – Madhav Anadkat Nov 08 '17 at 13:16
  • remember .. for this solution .. target="_blank" in string file is important. – Madhav Anadkat Nov 08 '17 at 13:19
  • @MadhavAnadkat not helped.. – Michele Lacorte Nov 14 '17 at 21:59
  • I tried this with your example, send me your code I will fix that for you. – Madhav Anadkat Nov 25 '17 at 11:06

0 Answers0