How to show android alert dialog in Webview?

前端 未结 5 2051
梦毁少年i
梦毁少年i 2021-02-04 19:39

I am Developing an app with webview but I don\'t know how to enable JavaScript to show alert dialog in webview.

I ever tried this one but it\'s isn\'t work for me. first

5条回答
  •  孤街浪徒
    2021-02-04 20:06

    Try this code:

    public OnClickListener imageButtonViewOnClickListener = new OnClickListener() {
    public void onClick(View v) {
    
    LayoutInflater inflater = LayoutInflater.from(MyActivity.this);
    
    // error here
    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();
    }
    };
    

    XML:

    
    
    
    

提交回复
热议问题