本文介绍了网址未加载到Webview中,但加载到了Android浏览器中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
某些类型的Urls无法在Webview的应用程序中加载,但可以在设备浏览器中加载.以下是在我的代码中无法正常工作的示例网址-" http://apps.takeyourapp.com/testApp/staging/index.html"
Some type of Urls are not loading in my app in Webview but it can be loaded in device browser. Following is the example Url which is not working in my code-"http://apps.takeyourapp.com/testApp/staging/index.html"
package com.example.webviewdemo;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.LinearLayout.LayoutParams;
public class MainActivity extends Activity {
WebView webViewPlaceholder;
String URL = "http://apps.takeyourapp.com/testApp/staging/index.html";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webViewPlaceholder = (WebView) findViewById(R.id.webholder);
webViewPlaceholder.getSettings().setJavaScriptEnabled(true);
webViewPlaceholder
.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
webViewPlaceholder.setScrollbarFadingEnabled(true);
webViewPlaceholder.getSettings().setLoadsImagesAutomatically(true);
webViewPlaceholder.getSettings().setUseWideViewPort(true);
webViewPlaceholder.loadUrl(URL);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
推荐答案
创建 WebViewClient
并像
public class myWebClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
}
和 setWebViewClient
一样:
webView.setWebViewClient(new myWebClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://apps.takeyourapp.com/testApp/staging/index.html");
,还将 INTERNET
权限添加到 manifest.xml
<uses-permission android:name="android.permission.INTERNET" />
这篇关于网址未加载到Webview中,但加载到了Android浏览器中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!