Android How to show links in web view?

Does anyone know a way to display a URL in a web view as

enter image description here

But here I get As here, there is no focus, and not one click option works, give me some tips, please.

enter image description here

this code uses the displayed data in webview

webview.getSettings().setJavaScriptEnabled(true); webview.loadDataWithBaseURL(null, string, "text/html", "utf-8", null); 
+6
source share
5 answers

String str = "Your text is 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); 
+5
source

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"); 
+8
source

Try it.....

 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 load a string of html texts in a 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. Do not forget to put your html file in your resources folder.

Hooray !!!: D

+2
source

Code example:

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 the display of automatic links for web browsing

+1
source

Please add android: autoLink = "web" in the 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" /> 
+1
source

All Articles