WebView未显示标准浏览器选项菜单

时间:2013-03-15 07:39:34

标签: android browser menu webview option

早上好, 我希望当用户打开我的自定义WebView时,当他点击菜单按钮时,标准浏览器的菜单会出现(下一个,上一个,分享链接,书签等)。

如何? : - )

这是我的代码:

   public class WebViewActivity extends Activity {


    private static final String TAG = "WebViewActivity";

    WebView mWebView;
    ProgressBar loadingProgressBar, loadingTitle;

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

        Shared.openedActivities.add(this);

        String url = this.getIntent().getExtras().getString("url");

        mWebView = (WebView) findViewById(R.id.webview);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.loadUrl(url);
        mWebView.setWebViewClient(new MyWebViewClient());

        WebSettings webSettings = mWebView.getSettings();
        webSettings.setPluginState(PluginState.ON);

        loadingProgressBar = (ProgressBar) findViewById(R.id.progressbar_Horizontal);

        mWebView.setWebChromeClient(new WebChromeClient() {

            // this will be called on page loading progress
            @Override
            public void onProgressChanged(WebView view, int newProgress) {

                super.onProgressChanged(view, newProgress);

                loadingProgressBar.setProgress(newProgress);


            // hide the progress bar if the loading is complete
                if (newProgress == 100) {
                    loadingProgressBar.setVisibility(View.GONE);

                } else {
                    loadingProgressBar.setVisibility(View.VISIBLE);

                }

            }

        });

    }

    public void onDestroy() {
        super.onDestroy();
        Trace.w(TAG, "onDestroy()");

        Shared.unbindDrawables(findViewById(R.id.rootWebViewActivity));
        System.gc();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if (keyCode == KeyEvent.KEYCODE_BACK) {
            finish();
        }
        return super.onKeyDown(keyCode, event);
    }

    private class MyWebViewClient extends WebViewClient {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            view.loadUrl(url);
            return true;
        }
    }
}

1 个答案:

答案 0 :(得分:0)

抱歉,但这不起作用,您必须自己实现此功能。 WebView不是浏览器,它只是一个呈现Web页面的视图。其他一切都是Browser-App而不是WebView的功能。
不过,您可以按照此处所述访问浏览器的书签:Get browser history and search result in android