还有另一个这样的问题,除了我试图避免使用TextView,因为我没有附带此错误消息的XML文件。我在点击超链接文本时尝试将用户重定向到链接。这是我到目前为止的代码:
public void messageAlert(){
String link = "www.google.com";
new AlertDialog.Builder(this)
.setTitle("ErrorMessage")
.setMessage("You have a massive error. Please go to "+ link) // hyperlink here
.setIcon(R.drawable.ic_action_error)
.setPositiveButton("Continue", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int n){
}
})
.show();
}
任何帮助将不胜感激! 附:我是Android的初学者
答案 0 :(得分:0)
你需要在这个链接上使用一个href接受的答案显示一个很好的例子。 a href example
TextView tv1 = new TextView(this);
tv1.setText(Html.fromHtml("<a href=\"" + "http:\\www.google.com" + "\">" + "Go to google" + "</a>"));
tv1.setClickable(true);
tv1.setMovementMethod(LinkMovementMethod.getInstance());
只需将此TextView添加到对话框中,它就会显示Go to google作为普通超级链接,点击此按钮将打开浏览器并搜索http:\ www.google.com