7

有谁知道像这样在 webview 中显示 URL 的方法

在此处输入图像描述

但是在这里我得到这样的结果,这里没有焦点,没有点击选项不起作用,请给我一些建议。

在此处输入图像描述

此代码使用 webview 中的显示数据

 webview.getSettings().setJavaScriptEnabled(true);
 webview.loadDataWithBaseURL(null, string, "text/html", "utf-8", null);
4

5 回答 5

11

使用Linkify.

Spannable sp = new SpannableString(Html.fromHtml(string));
Linkify.addLinks(sp, Linkify.ALL);
final String html = "<body>" + Html.toHtml(sp) + "</body>";
webView.loadData(html, "text/html", "utf-8");
于 2013-01-29T06:05:07.640 回答
7

String str="你的文字放在这里... http://stackoverflow.com/questions/14576507/android-how-to-display-links-in-webview-like-this";

ArrayList<String> myArray = new ArrayList<String>();

myArray.add( "<!DOCTYPE HTML><!-- created HTML PAGE -->");
myArray.add("<head> ");
myArray.add("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"  width=100%>");
myArray.add("<meta name=\"viewport\" content=\"width=device-width\">");
myArray.add("<style>");
myArray.add("   p { font-family:Arial, Helvetica, sans-serif;}");
myArray.add("</style>");
myArray.add("</head> ");
myArray.add("<body style=\"background-color: transparent; margin-left:5%; margin-right:5%; \">");

myArray.add("<div >");
Spannable sp = new SpannableString(str);
Linkify.addLinks(sp, Linkify.ALL);
str = Html.toHtml(sp) ;
myArray.add(str);

String myFullString = myArray.toString().replace("[", "").replace("]", "").replace(",", "\n").replace("&lt;", "<").replace("&gt;", ">");

mWebView.loadDataWithBaseURL("about:blank", myFullString ,"text/html", "utf-8", null);
于 2013-01-29T06:15:39.820 回答
1

示例代码:

爪哇:

 TextView t2 = (TextView) findViewById(R.id.text2);
 t2.setMovementMethod(LinkMovementMethod.getInstance());

安卓:

<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/yourid"
android:id="@+id/yourid"
android:layout_below="@+id/yourid" android:layout_centerInParent="true"
android:layout_marginTop="20dp"></TextView>

Android WebView:更改webview的自动链接显示

于 2013-01-29T05:58:36.960 回答
1

试试这个:

  String header = "< ?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
  String data = "< html>< body>< a href='tel:555-5599'>508-776-5510
  " "< /body>< /html>";
  mWebView.loadData(header+data,  "text/html", "UTF-8");

如果要将一串 html 文本加载到 webView 中,则可以使用:

mWebView.loadData(header+data,  "text/html", "UTF-8");

如果你有一个 html 文件,那么你可以使用:

webView.loadUrl("file:///android_asset/mypage.html"):

注意:不要忘记将您的 html 文件放在您的资产文件夹中。

干杯!!!:D

于 2013-01-29T06:06:30.230 回答
1

请在您的 TextView 中添加 android:autoLink="web"

 <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/tv_text"
        android:autoLink="web"  
        android:textColorLink="@color/link"
        android:text="click here to load www.fb.com"
        android:textColor="@color/black" />
于 2018-01-17T06:59:04.043 回答