0

早上好,我希望当用户打开我的自定义 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;
        }
    }
}
4

1 回答 1

0

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

于 2013-03-15T07:46:39.987 回答