How to display HTML text in AlertDialog
package com.codingwithsara.myapplication; | |
import android.content.DialogInterface; | |
import android.support.v7.app.AlertDialog; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.text.Html; | |
import android.text.method.LinkMovementMethod; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
String message = "<p>Thank you for watching this video!</p>" + | |
"<p><b>My Website</b> : <a href=\"https://codingwithsara.com\">Tap Here</a></p>"; | |
AlertDialog alertDialog = new AlertDialog.Builder(this) | |
.setTitle("Hello") | |
.setMessage(Html.fromHtml(message)) | |
.setPositiveButton("OK", new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialogInterface, int i) { | |
// Do something | |
} | |
}) | |
.show(); | |
((TextView) alertDialog.findViewById(android.R.id.message)) | |
.setMovementMethod(LinkMovementMethod.getInstance()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment