首页 新闻 会员 周边

如何用webview实现弹出页面

0
悬赏园豆:100 [已关闭问题] 关闭于 2012-07-02 09:53

如何所示,这个图是用自带的浏览器打开的,如何用webview控件自己写一个这个功能

问题补充:

可能我没有说清楚,这个才是问题的核心:

在webview里点击链接(链接是用JS window.open打开的),弹出如上的窗口,并返回赋值(赋值也是js的 window.opener.document.getElementById("txtCH").value = document.getElementById("txt1").value;)。

并且我试了安卓上的其他浏览器基本都不能满足要求,只有系统自带的这个可以。

重要的一点服务器的代码是不能修改的。

weipt的主页 weipt | 初学一级 | 园豆:26
提问于:2012-06-12 11:56
< >
分享
所有回答(2)
0

应该用popupwindow或者类似的弹出窗口吧,截取webview中的点击操作,用webview本身应该没这功能

Qiengo | 园豆:184 (初学一级) | 2012-06-12 13:10

谢谢回复,但是不知道这个是不是popupwindow,如果是的话怎么让新打开的页面在这里呢

支持(0) 反对(0) weipt | 园豆:26 (初学一级) | 2012-06-12 13:49

@weipt:  First you need to Override the onJSAlert() method in the WebChromeClient class to enable popup window in webview:


public class MyWebChromeClient extends WebChromeClient {
        @Override
        public boolean onJsAlert(WebView view, String url, String message, JsResult jsResult) {
            final JsResult finalJsResult = jsResult;
            new AlertDialog.Builder(view.getContext()).setMessage(message).setPositiveButton(android.R.string.ok, new AlertDialog.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    finalJsResult.confirm();
                }
            }).setCancelable(false).create().show();
            return true;
        }
    }

and add this to your webview:

MyWebChromeClient myWebChromeClient = new MyWebChromeClient();
webView.setWebChromeClient(myWebChromeClient);

Then you can add custom webview in your AlertDialog (to replace the AlertDialog above):

public OnClickListener imageButtonViewOnClickListener = new OnClickListener() {
        public void onClick(View v) {

            LayoutInflater inflater = LayoutInflater.from(MyActivity.this);             
            View alertDialogView = inflater.inflate(R.layout.alert_dialog_layout, null);
            WebView myWebView = (WebView) findViewById(R.id.DialogWebView);
            myWebView.loadData(webContent, "text/html", "utf-8");
            AlertDialog.Builder builder = new AlertDialog.Builder(MyActivity.this);
            builder.setView(alertDialogView);
            builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            }).show();
        }
    };

该方法貌似起作用,没试过,源地址:http://stackoverflow.com/questions/6193014/what-is-this-webview-popup-dialog

 

 

支持(0) 反对(0) Qiengo | 园豆:184 (初学一级) | 2012-06-12 14:12
0

需要在html里写JavaScript代码 然后在webview的代理中捕获

具体点吧

支持(0) 反对(0) weipt | 园豆:26 (初学一级) | 2012-06-12 13:49
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册