开发者

android webview and loadData, can i get the back button to return to generated content?

开发者 https://www.devze.com 2023-03-17 16:56 出处:网络
I have an android webview that displays generated content with loadDataWithBaseURL. Looks great. However, if i follow a link and then hit the back button I get a blank page where I\'d like to see my g

I have an android webview that displays generated content with loadDataWithBaseURL. Looks great. However, if i follow a link and then hit the back button I get a blank page where I'd like to see my generated content.

does开发者_运维技巧 anyone know how I can use the back button to return to my generated content?


Try this:

mWebView.setOnKeyListener(new OnKeyListener() {
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        switch(keyCode)
        {
            case KeyEvent.KEYCODE_BACK:
                if(mWebView.canGoBack() == true){
                    mWebView.goBack();
                    return true;
                } else
                    return false;   
                }

                return false;
            }
        });
0

精彩评论

暂无评论...
验证码 换一张
取 消