0

我想禁用手机浏览器,我想使用 webview。但这段代码对我不起作用。请指导我:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Wop=(WebView)findViewById(R.id.webi);

        String mturl="http://www.google.com";
        Wop.getSettings().setJavaScriptEnabled(true);

        Wop.loadUrl(mturl);
        }
4

2 回答 2

1
            mWebView = (WebView) findViewById(R.id.webview);
            mWebView.getSettings().setJavaScriptEnabled(true);
            mWebView.setWebViewClient(new HelloWebViewClient());
            mWebView.loadUrl("http://www.stackoverflow.com");

要加载以前的网页,

public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
            mWebView.goBack();
            return true;
        } }

类的定义HelloWebViewClient

private class HelloWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            // TODO Auto-generated method stub
            super.onPageFinished(view, url);


            //what you want to do when the page finished loading, eg. give some message, show progress bar, etc
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // TODO Auto-generated method stub
            super.onPageStarted(view, url, favicon);

            //what you want to do when the page starts loading, eg. give some message
        }


    }
于 2012-09-02T13:26:23.310 回答
-1
WebView w = new WebView(this);

//将此添加到您的代码中

 w.setWebViewClient(new Callback());
 w.loadUrl("http://www.facebook.com");

//还有这个类

private class Callback extends WebViewClient{  //HERE IS THE MAIN CHANGE. 

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return (false);
            }

        }
于 2012-09-06T11:41:39.547 回答