我正在编写一个应用程序来在我的活动中启动 webView。但它是在网络浏览器中启动的。
但是当我使用时shouldOverrideUrlLoading
,我只能得到空白屏幕。
对于那个问题,我参考了这个链接
但是在我的情况下没有人帮助..
我已经给出了我的代码。
请注意我犯了什么错误?
我的代码是:
webview.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical" >
<WebView
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal|center_vertical" >
</WebView>
</LinearLayout>
WebViewActivity.java
public class webViewActivity extends Activity {
private WebView webView;
private String strUrl;
public final String TAG = "webViewActivity";
ProgressBar progBar;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.webview);
Bundle bundle = getIntent().getExtras();
strUrl = bundle.getString("URL");
Log.d(TAG, "link is " + strUrl);
// strUrl = "www.google.com";
webView = new WebView(this);
webView.loadUrl(strUrl);
// progBar = (ProgressBar)findViewById(R.id.progWeb);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(strUrl);
return true;
}
});
}
请帮助纠正我的错误。
先感谢您!!