android webview显示空白页 [英] android webview displaying blank page

查看:1724
本文介绍了android webview显示空白页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序,我正在开发使用运行在Android 2.3.3上的模拟器,嵌入式WebView嵌入在线性布局(垂直)中的framelayout中。不管我使用什么代码,它从来没有做任何事情。我有权限将Android应用程序设置为INTERNET。
即使在加载HTML代码时也是如此。我得到一个空白的白页,没有错误没有什么。没有在logcat中。

  WebView wview =(WebView)findViewById(R.id.webView1); 
wview.getSettings()。setJavaScriptEnabled(true);

我已经尝试所有三个尝试加载任何内容到webview:

  wview.loadUrl(http://www.google.com); 
wview.loadData(< HTML>< BODY>< H3> Test< / H3>< / BODY>< / HTML>,text / html,utf-8 ;
wview.loadDataWithBaseURL(null,< HTML>< BODY>< H3> Test< / H3>< / BODY>< / HTML>,text / html,utf-8 ,空值);

所有这三个都给我相同的结果。没有什么。



任何想法?

解决方案

可能有点太晚了,但是我想和大家分享一下我的经验,因为我有同样的问题,花了很多时间。



WebView 放在 RelativeLayout / strong>而不是 FrameLayout



我测试过的是: code> WebView 的 onPageFinished()每次都被调用,但在屏幕上我有空白页。从 chrome:// inspect WebView 调试器我能够ping我的 WebView 通过按 inspect 按钮,之后 WebView 立即刷新。我的想法 - WebView FrameLayout RelativeLayout 修复问题(即使 invalidate() requestLayout()调用没有帮助) p>

I have an android application that I am developing using the emulator running on android 2.3.3 with an embedded WebView in a framelayout nested in a linearlayout (vertical). No matter what code I use it never actually does anything. I have Permissions on the android application set to INTERNET. Even when trying to load just the HTML code. I get a blank white page, no errors no nothing. Nothing in logcat as well.

WebView wview = (WebView)findViewById(R.id.webView1);
wview.getSettings().setJavaScriptEnabled(true);

I have tried all three of these to attempt to load anything into the webview:

wview.loadUrl("http://www.google.com");
wview.loadData("<HTML><BODY><H3>Test</H3></BODY></HTML>","text/html","utf-8");
wview.loadDataWithBaseURL(null, "<HTML><BODY><H3>Test</H3></BODY></HTML>","text/html","utf-8",null);

All three give me the same results. Nothing.

Any ideas?

解决方案

It might be a bit too late, but I wanted to share my experience with you, because I had the same problem and spent a lot of time on it.

Put your WebView in RelativeLayout and not in FrameLayout.

What I have tested: My WebView's onPageFinished() was called every time, but on the screen I got blank page. From chrome://inspect WebView debugger I was able to "ping" my WebView by pressing inspect button, and after that WebView was refreshing immediately. My thoughts - WebView isn't rendered correctly in FrameLayout, and RelativeLayout fixes the issue (even invalidate() and requestLayout() calls didn't help).

这篇关于android webview显示空白页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆