1

我需要完全执行此操作,但在 Android 上:

Java:用可点击的 HTML 链接替换文本 URL

我已经尝试过此解决方案中提供的示例(适用于 Java),但没有奏效。

这就像正则表达式不起作用。

有什么解决办法吗?

谢谢!


这是我的代码:

            final EditText postTextView = (EditText) findViewById(R.id.postText);
            Intent output = new Intent();
            String text = postTextView.getText().toString();

            text = text.replaceAll("(.*://[^<>[:space:]]+[[:alnum:]/])", "<a href=\"$1\">HereWasAnURL</a>");

System.out.println("* * * Converted = " + text.replaceAll("(.*://[^<>[:space:]]+[[:alnum:]/])", "HereWasAnURL" ));

            output.putExtra(ZNMainActivity.RESULT_CODE_POST, text );
            setResult(RESULT_OK, output);
            finish();       
4

1 回答 1

3

在你的 EditText 中做这样的事情

EditText editText = (EditText) findViewById(R.id.edittext);
editText.setText(someContent);
Linkify.addLinks(editText, Linkify.ALL);
Log.d(TAG, "HTML: " + Html.toHtml(editText.getEditableText()));

请参阅http://developer.android.com/reference/android/text/util/Linkify.html中的详细信息

于 2013-03-04T07:34:50.397 回答