webView.loadUrl显示空白屏幕 [英] webView.loadUrl displays a blank screen
问题描述
我要加载这些<一个href=\"http://files.flipsnack.com/iframe/embed.html?hash=fdk843nc&wmode=window&bgcolor=EEEEEE&t=1381431045%22%20width=%22640%22%20height=%22385%22%20seamless=%22seamless%22%20scrolling=%22no%22%20frameborder=%220%22%20allowtransparency=%22true%22\"相对=nofollow> URL使用的下面$ C显示为output.you可以检查 URL $ c.But终于黑屏
$之间的联系C $ c。在最后一行
。
WebPagerLoader.java:
公共类WebPageLoader扩展活动
{最后活动活动=这一点;
私人字符串HTML;
@覆盖
公共无效的onCreate(捆绑savedInstanceState)
{
super.onCreate(savedInstanceState);
。this.getWindow()requestFeature(Window.FEATURE_PROGRESS);
的setContentView(R.layout.activity_main);
web视图的WebView =(的WebView)findViewById(R.id.webview);
webView.getSettings()setJavaScriptEnabled(真)。 webView.setWebChromeClient(新WebChromeClient(){
公共无效onProgressChanged(的WebView观点,诠释进度)
{
activity.setTitle(正在加载...);
activity.setProgress(进度* 100); 如果(==进度100)
activity.setTitle(R.string.app_name);
}
}); webView.setWebViewClient(新WebViewClient(){
@覆盖
公共无效onReceivedError(的WebView观点,诠释错误code,描述字符串,字符串failingUrl)
{ } @覆盖
公共布尔shouldOverrideUrlLoading(的WebView视图,字符串URL)
{
view.loadUrl(URL);
返回true;
}
}); webView.loadUrl(&LT; IFRAME src=\\\"http://files.flipsnack.com/iframe/embed.html?hash=fdk843nc&wmode=window&bgcolor=EEEEEE&t=1381431045\\\"宽度= \\640 \\HEIGHT = \\385 \\无缝= \\无缝\\SCROLLING = \\无\\FRAMEBORDER = \\0 \\ALLOWTRANSPARENCY = \\真正\\&GT;&LT; / IFRAME&gt;中;
}
}
清单:
&LT;?XML版本=1.0编码=UTF-8&GT?;
&LT;清单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=com.webpageloader
安卓版code =1
机器人:=的versionName1.0&GT; &LT;用途-SDK
安卓的minSdkVersion =14
机器人:targetSdkVersion =19/&GT; &LT;使用许可权的android:NAME =android.permission.INTERNET对/&GT; &lt;应用
机器人:allowBackup =真
机器人:图标=@绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME
机器人:主题=@风格/ AppTheme&GT;
&LT;活动
机器人:名字=com.webpageloader.WebPageLoader
机器人:标签=@字符串/ APP_NAME&GT;
&所述;意图滤光器&gt;
&lt;作用机器人:名字=android.intent.action.MAIN/&GT; &LT;类机器人:名字=android.intent.category.LAUNCHER/&GT;
&所述; /意图滤光器&gt;
&LT; /活性GT;
&LT; /用途&gt;&LT; /清单&GT;
我终于得到了黑屏
。我不知道我做了什么错webView.loadUrl
。
我不知道如何解决these.Anybody可以帮助我与这些problem.Thank你。</ P>
更改
webView.loadUrl(&LT; IFRAME src=\\\"http://files.flipsnack.com/iframe/embed.html?hash=fdk843nc&wmode=window&bgcolor=EEEEEE&t=1381431045\\\"宽度= \\640 \\HEIGHT = \\385 \\无缝= \\无缝\\SCROLLING = \\无\\FRAMEBORDER = \\0 \\ALLOWTRANSPARENCY = \\真正\\&GT;&LT; / IFRAME&gt;中;
到
webView.loadDataWithBaseURL(NULL,&LT; IFRAME src=\\\"http://files.flipsnack.com/iframe/embed.html?hash=fdk843nc&wmode=window&bgcolor=EEEEEE&t=1381431045\\\"宽度= \\640 \\HEIGHT = \\385 \\无缝= \\无缝\\SCROLLING = \\无\\FRAMEBORDER = \\0 \\ALLOWTRANSPARENCY = \\真正\\&GT;&LT; / IFRAME&gt;中text / html的,UTF-8,NULL);
的 loadDataWithBaseURL()
方法需要,其它参数中,基地URL解决了HTML相对URL时使用。任何相对URL(例如)将PTED视为相对于()提供给loadDataWithBaseURL基础URL间$ P $。如果你发现你有拒绝与loadData(正常加载内容),尽量loadDataWithBaseURL()与空基URL,因为有时工作得更好,原因不明。
I have to load these Url by using the below code.But finally blank screen displayed as a output.you can check theurl
link between code at the last line
.
WebPagerLoader.java:
public class WebPageLoader extends Activity
{
final Activity activity = this;
private String html;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.activity_main);
WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
activity.setTitle("Loading...");
activity.setProgress(progress * 100);
if(progress == 100)
activity.setTitle(R.string.app_name);
}
});
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
{
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
webView.loadUrl("<iframe src=\"http://files.flipsnack.com/iframe/embed.html?hash=fdk843nc&wmode=window&bgcolor=EEEEEE&t=1381431045\" width=\"640\" height=\"385\" seamless=\"seamless\" scrolling=\"no\" frameborder=\"0\" allowtransparency=\"true\"></iframe>";
}
}
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.webpageloader"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.webpageloader.WebPageLoader"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
finally I get a blank screen
.I doesn't know what I did wrong in webView.loadUrl
.
I doesn't know how to solve these.Anybody can help me with these problem.Thank You.
Change your
webView.loadUrl("<iframe src=\"http://files.flipsnack.com/iframe/embed.html?hash=fdk843nc&wmode=window&bgcolor=EEEEEE&t=1381431045\" width=\"640\" height=\"385\" seamless=\"seamless\" scrolling=\"no\" frameborder=\"0\" allowtransparency=\"true\"></iframe>";
to
webView.loadDataWithBaseURL(null, "<iframe src=\"http://files.flipsnack.com/iframe/embed.html?hash=fdk843nc&wmode=window&bgcolor=EEEEEE&t=1381431045\" width=\"640\" height=\"385\" seamless=\"seamless\" scrolling=\"no\" frameborder=\"0\" allowtransparency=\"true\"></iframe>", "text/html", "UTF-8", null);
The loadDataWithBaseURL()
method takes, among other parameters, the "base URL" to use when resolving relative URLs in the HTML. Any relative URL (e.g., ) will be interpreted as being relative to the base URL supplied to loadDataWithBaseURL(). If you find that you have content that refuses to load properly with loadData(), try loadDataWithBaseURL() with a null base URL, as sometimes that works better, for unknown reasons.
这篇关于webView.loadUrl显示空白屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!