如何在Android AlertDialog中获得可点击的HTML内部(锚点)链接?

时间:2014-08-31 14:57:22

标签: android html

是否可以在AlertDialog中设置可点击的内部链接(锚链接)?此链接不应调用外部网页,只应跳转到achor链接。 我用href =&#34;#jumptarget&#34;和<a name="jumptarget">。但是我收到了一个错误。

我的HTML代码:

 <!DOCTYPE html>
 <html>
  <body>
  <h1><a name="jumpstart" href="#jumptarget">Jump</a></h1> 
  <p>Some Text... </p>
  <h1><a name="jumptarget">Jump Target</a></h1>
  </body>
  </html>

我的Java代码:

    int listId = R.raw.instructions;
    String instructions = "";
    instructions = loadTextRessource(listId);
    TextView msg = new TextView(this);
    msg.setText(Html.fromHtml(instructions));
    msg.setMovementMethod(LinkMovementMethod.getInstance());
    msg.setClickable(true);
    AlertDialog.Builder alertDlg = new AlertDialog.Builder(this);
    alertDlg.setTitle("Instructions" );
    alertDlg.setView(msg);
    alertDlg.setPositiveButton("OK", null);
    alertDlg.show();

显示的结果是可点击的,但我得到一个ActivityNotFoundException异常。

1 个答案:

答案 0 :(得分:0)

我找到了一个解决方案:使用WebView而不是TextView