Skip to content

Instantly share code, notes, and snippets.

@codingwithsara
Created April 25, 2019 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codingwithsara/a24e9db011c440088f618b878b90edbd to your computer and use it in GitHub Desktop.
Save codingwithsara/a24e9db011c440088f618b878b90edbd to your computer and use it in GitHub Desktop.
AlertDialog - HTML
package jp.codeforfun.test;
import android.app.AlertDialog;
import android.content.DialogInterface;
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 = "Google検索は<br><a href=\"http://google.com\">こちら</a>";
AlertDialog alert = new AlertDialog.Builder(this)
.setTitle("タイトル")
.setMessage(Html.fromHtml(message))
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//「OK」が押された時の処理を書く 
}
})
.show();
((TextView) alert.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