gpt4 book ai didi

android - 如果 "display:none",文件选择器对话框不会在 android webview 中打开

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:56:17 24 4
gpt4 key购买 nike

开发者早上好

嗯,我做了一个 android webview 应用程序,我遇到了一个小问题,我搜索了很多但找不到任何有效的解决方案。

好的。问题是。我有这样的 php/Html 代码

 <input type="file" name="banner_image" style="display:none;" id="banner_image" onChange="fileSelected('banner');" accept="image/*" />

注意 style="display:none;"

我正在从 div 的 onClick 调用输入字段的 onclick 事件像这样通过 Jquery

<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");
}

它没有打开我的文件选择器对话框。

但是当我删除这个 display:none;从我上面的代码来看,它工作正常。我在 iPhone 中测试了它在两种情况下都工作正常但在 android webview 中它没有调用我的文件选择器对话框同时保持 display:none .

问题我必须让我的浏览按钮在我的网页上不可见,因为它的模板/设计要求 ( which I have done with 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, "File Chooser"),
MainActivity.FILECHOOSER_RESULTCODE);
}

});

}

只是重复我的问题:文件选择器在保持 display:none 的同时没有打开在<input name="banner_image" style="display:none;" id="banner_image" onChange="fileSelected('banner');" type="file" accept="image/*" />

最佳答案

如果您使用 display:none,输入文件将不起作用

只要把它放在可视区域之外,例如 position: absolute;left: -500px;

关于android - 如果 "display:none",文件选择器对话框不会在 android webview 中打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20064468/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com