Webview始终以桌面模式启动

时间:2013-09-05 08:09:18

标签: java android android-webview user-agent mobile-website

这是两天我无法在移动模式下直接启动我的网页浏览。当我第一次打开应用程序时,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/");
        }


    } 

即使我改变了用户代理也行不通!我试着各方面。我希望得到某人的帮助,谢谢。

1 个答案:

答案 0 :(得分:0)

在loadUrl()

之前添加此行
webview.setWebViewClient(new WebViewClient());