早上好开发者
好吧,我已经制作了一个android webview应用程序,我面临一个小问题,我搜索了很多,但找不到任何有效的解决方案.
<input type="file" name="banner_image" style="display:none;" id="banner_image" onChange="fileSelected('banner');" accept="image/*" />
注意:style =“display:none;”
我通过像这样的Jquery从div的onClick调用输入字段的onclick事件
<div class="profile-pic-txt" onClick="openFileDialog('profile');"> Click here to add Profile Picture <p>200px/200px</p> </div>
这是我的java脚本openFileDialog()函数
function openFileDialog(test) { $("#banner_image").click(); console.log("Test"); }
它没有打开我的文件选择器对话框.
但当我删除此显示:无;从我上面的代码它只是工作正常.我在iPhone中测试了它在两种情况下的工作正常,但在android webview中它没有调用我的文件选择器对话框,同时保持display:none.
题
我必须使我的浏览按钮在我的网页上不可见,因为它的模板/设计要求(我用display:none完成)
在最后这里是我的android webview配置代码.
private void configureWebview() { webView.getSettings().setDefaultZoom(ZoomDensity.FAR); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); webView.getSettings().setBuiltInZoomControls(true); webView.getSettings().setLoadWithOverviewmode(true); webView.getSettings().setCacheMode(MODE_APPEND); webView.getSettings().setUseWideViewPort(true); webView.getSettings().setRenderPriority(RenderPriority.HIGH); webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); webView.setWebViewClient(new MyWebViewClient()); webView.setWebChromeClient(new WebChromeClient() { @Override public boolean onConsoleMessage(ConsoleMessage cm) { Log.e("Console Webview",cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId()); return true; } // For Android < 3.0 @SuppressWarnings("unused") public void openFileChooser(ValueCallback<Uri> uploadMsg) { uploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); MainActivity.this.startActivityForResult( Intent.createChooser(i,"File Chooser"),FILECHOOSER_RESULTCODE); } // For Android 3.0+ @SuppressWarnings("unused") public void openFileChooser(ValueCallback<Uri> uploadMsg,String acceptType) { uploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); MainActivity.this.startActivityForResult( Intent.createChooser(i,"File Browser"),FILECHOOSER_RESULTCODE); } // For Android 4.1 @SuppressWarnings("unused") public void openFileChooser(ValueCallback<Uri> uploadMsg,String acceptType,String capture) { uploadMessage = uploadMsg; Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.addCategory(Intent.CATEGORY_OPENABLE); i.setType("image/*"); MainActivity.this.startActivityForResult( Intent.createChooser(i,MainActivity.FILECHOOSER_RESULTCODE); } }); }
只是重复我的问题:在< input name =“banner_image”style =“display:none;”中保持display:none时,文件选择器没有打开id =“banner_image”onChange =“fileSelected('banner');” type =“file”accept =“image / *”/>
解决方法
如果使用display:none,则输入文件不起作用
只是把它放在可视区域之外,例如位置:绝对;左:-500px;