问题描述
我在Android开发中新建,我正在尝试官方Android网站的WebView榜样.
http://developer.android.com/guide/tutorials/views/hello-webview.html
但我做的一切都说......这很简单:我创建项目,编辑布局文件,然后我添加代码等.没有问题建设......但是当我在模拟器启动应用程序时我刚收到一个黑色屏幕.它就像如果布局是空的...类似于WebView未创建.
我做错了什么?
推荐答案
抱歉那个 - 该链接有点过时.此教程的固定版本可用:
http://developer.android.com/guide/webapps/webview.html
我们应该删除旧链接;我会提交一个错误.
并注意,错误是setContentView未被调用.
在oncreate方法中其他推荐答案
添加WebView.enablePlatformNotifications();
在清单文件中添加<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
现在它可以很好...
其他推荐答案
webview_id = (WebView)findViewById(R.id.webview_id); webview_id.getSettings().setJavaScriptEnabled(true); // enable javascript WebSettings webSettings = webview_id.getSettings(); webSettings.setBuiltInZoomControls(true); webSettings.setDisplayZoomControls(true); webSettings.setPluginState(WebSettings.PluginState.ON); webSettings.setJavaScriptEnabled(true); webview_id.setInitialScale(90); webSettings.setLoadWithOverviewMode(true); webview_id.requestFocusFromTouch(); webview_id.setWebViewClient(new WebViewClient() { public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Snackbar.with(getApplicationContext()).dismiss(); Snackbar.with(getApplicationContext()) // context .text(description) // text to display .show(MainActivity.this); } public void onPageFinished(WebView view, String url) { progressBar.setVisibility(View.GONE); } }); if(isNetworkAvailable()){ webview_id .loadUrl("http://helloworld.org/"); }else{ Snackbar.with(getApplicationContext()).dismiss(); Snackbar.with(getApplicationContext()) // context .text("Please Check your Internet Connection") // text to display .show(MainActivity.this); progressBar.setVisibility(View.VISIBLE); } }
问题描述
I'm new in android development and I am trying out the WebView example in the official android site.
http://developer.android.com/guide/tutorials/views/hello-webview.html
But I do everything they say...which is pretty simple: I create the project, edit the layout file, then I add the code, etc. No problems building...but when I launch the app in the simulator I just got a black screen. It is like if the Layout is empty...like if the WebView is not created.
What am I doing wrong?
推荐答案
Sorry about that – that link is a bit outdated. The fixed version of this tutorial is available here:
http://developer.android.com/guide/webapps/webview.html
We should remove the old link; I'll file a bug.
And note, the error is that setContentView isn't being called.
其他推荐答案
in oncreate method add WebView.enablePlatformNotifications();
in manifest file add
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
now it works fine...
其他推荐答案
webview_id = (WebView)findViewById(R.id.webview_id); webview_id.getSettings().setJavaScriptEnabled(true); // enable javascript WebSettings webSettings = webview_id.getSettings(); webSettings.setBuiltInZoomControls(true); webSettings.setDisplayZoomControls(true); webSettings.setPluginState(WebSettings.PluginState.ON); webSettings.setJavaScriptEnabled(true); webview_id.setInitialScale(90); webSettings.setLoadWithOverviewMode(true); webview_id.requestFocusFromTouch(); webview_id.setWebViewClient(new WebViewClient() { public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { Snackbar.with(getApplicationContext()).dismiss(); Snackbar.with(getApplicationContext()) // context .text(description) // text to display .show(MainActivity.this); } public void onPageFinished(WebView view, String url) { progressBar.setVisibility(View.GONE); } }); if(isNetworkAvailable()){ webview_id .loadUrl("http://helloworld.org/"); }else{ Snackbar.with(getApplicationContext()).dismiss(); Snackbar.with(getApplicationContext()) // context .text("Please Check your Internet Connection") // text to display .show(MainActivity.this); progressBar.setVisibility(View.VISIBLE); } }