Android How to Display Links in webview like this?

2019-04-28 09:51发布

Does anyone know of a way to Display URL's in webview like this

enter image description here

But here I am geting Like this here no focus and no click option not working any thing give me some sugessions please..

enter image description here

this code useing display data in webview

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

5条回答
The star\"
2楼-- · 2019-04-28 10:30

Sample code:

Java:

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

android:

<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: Change Auto-Link Display for webview

查看更多
Rolldiameter
3楼-- · 2019-04-28 10:33

Please Add android:autoLink="web" in your TextView

 <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" />
查看更多
SAY GOODBYE
4楼-- · 2019-04-28 10:34

Use 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");
查看更多
Viruses.
5楼-- · 2019-04-28 10:37

String str="Your text goes here... 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);
查看更多
\"骚年 ilove
6楼-- · 2019-04-28 10:48

Try this:

  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");

If you are loading a string of html texts into webView then you can use:

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

If you have an html file then you can use:

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

Note: Dont forget to put your html file in your assets folder.

Cheers!!! :D

查看更多
登录 后发表回答