1

这两天我无法直接在移动模式下启动我的 webview。当我第一次打开应用程序时,webview 会显示桌面。我的代码

@Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_INDETERMINATE_PROGRESS); // Request     progress circle
        setContentView(R.layout.main);
        webview = (WebView) findViewById(R.id.webview);
        WebSettings websettings = webview.getSettings();
        websettings.setJavaScriptEnabled(true);

        webview.getSettings().setUserAgentString("Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en)AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3");
        setProgressBarIndeterminateVisibility(true); // Show progress circle

        final Activity activity = this;

        webview.setWebChromeClient(new WebChromeClient(){

                public void onProgressChanged(WebView view, int progress) {
                    activity.setTitle("Loading...");
                    activity.setProgress(progress * 100);
                    if(progress == 100)
                        setProgressBarIndeterminateVisibility(false); // Hide progress circle when page loaded
                    activity.setTitle("Title");
                }
            });
        if (savedInstanceState == null)
        {
            webview.loadUrl("http://forum.ubuntu-it.org/");
        }


    } 

即使我更改了用户代理也不起作用!我尝试了各种方式。我希望得到某人的帮助,谢谢。

4

1 回答 1

0

在 loadUrl() 之前添加这一行

webview.setWebViewClient(new WebViewClient());
于 2013-09-05T08:10:46.443 回答