简体   繁体   English

WebView无法使用普通URL启动

[英]WebView does not launch with a normal URL

My WebView does not launch with a normal URL 我的WebView不能使用普通URL启动

I have done everything I could, The browser is simply not launching... I have tried attaching webclient too, doesnt works. 我已经做了一切我可以做的,浏览器根本无法启动...我也尝试附加webclient,但是不起作用。 I have the internet permission in the manifest. 清单中有互联网许可。 Could anyOne help me here? 有人可以帮我吗? :( :(
Its so simple and its not workin. 它是如此简单,而且不起作用。

void somemethod()
   {
  WebView myWebView = new WebView(mycontext);
  myWebView.loadUrl("http://stackoverflow.com/questions/5066778/android-html-image-prob");
   }        

This is not the code to launch a browser bro. 这不是启动浏览器的代码。 This is the code to open url into the embedded webview inside the app. 这是将url打开到应用程序内嵌式webview中的代码。

To open the url in Android's default browser try this 要在Android的默认浏览器中打开网址,请尝试以下操作

Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(strURL));

startActivity(myIntent);

To open a url into the embedded browser, embed a webview in a layout and then call the second line in your code. 要在嵌入式浏览器中打开URL,请将Web视图嵌入布局中,然后在代码中调用第二行。

If you really want to use WebView instead of Browser intent, there is two way. 如果您确实要使用WebView而不是浏览器意图,则有两种方法。 One way is to declare a webview in layout file, connect it to Activity class and set some attributes and load the url. 一种方法是在布局文件中声明Webview,将其连接到Activity类并设置一些属性并加载url。

Other way is to declare the WebView dynamically. 另一种方法是动态声明WebView。 In that case you have to set necessary attributes, set layout parameters and you must add it to content view. 在这种情况下,您必须设置必要的属性,设置布局参数,并且必须将其添加到内容视图。 Then load the url. 然后加载URL。

Here is a tutorial Hello, WebView 这是一个教程你好,WebView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM