为了账号安全,请及时绑定邮箱和手机立即绑定

Webview 不适用于 HTML 选择元素

Webview 不适用于 HTML 选择元素

喵喵时光机 2022-07-14 17:27:58
所以我的 webview 不能使用 select 元素。换句话说,当我单击任何页面上的选择元素时,它不会显示菜单。html 选择元素示例:<select>    <option>test</option>    <option>testing it</option>    <option>bla bla bla</option></select>java创建我的webview:        NestedWebView nwv = new NestedWebView(activity.getApplicationContext());    nwv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));    registerForContextMenu(nwv);    nwv.setWebViewClient(new webViewClient());    nwv.setWebChromeClient(new webChromeClient(nwv));    nwv.addJavascriptInterface(new JSInterface(), "drconsole");    nwv.getSettings().setJavaScriptEnabled(true);    nwv.getSettings().setLoadWithOverviewMode(true);    nwv.getSettings().setUseWideViewPort(true);    nwv.getSettings().setSupportZoom(true);    nwv.getSettings().setBuiltInZoomControls(true);    nwv.getSettings().setDisplayZoomControls(false);    nwv.getSettings().setAllowFileAccess(true);    nwv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);    nwv.getSettings().setSupportMultipleWindows(true);    nwv.getSettings().setGeolocationEnabled(true);    nwv.setDrawingCacheEnabled(true);    nwv.getSettings().setPluginState(WebSettings.PluginState.ON);    nwv.loadUrl(url);    nwv.setDownloadListener(new DownloadListener(){        @Override        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength){            try{                DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));                String filename = new URL(url).getFile();                request.allowScanningByMediaScanner();                request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);                request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename.substring(filename.lastIndexOf('/')+1));            }        }    });我也几乎可以使用 webviewclient 和 webchromeclient 。请在对我的问题投票之前发表评论。
查看完整描述

1 回答

?
MYYA

TA贡献1868条经验 获得超4个赞

要修复此错误,必须使用活动而不是应用程序上下文来初始化 webview。

这一行:

NestedWebView nwv = new NestedWebView(activity.getApplicationContext());

一定是:

NestedWebView nwv = new NestedWebView(activity);


查看完整回答
反对 回复 2022-07-14
  • 1 回答
  • 0 关注
  • 112 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号