我了解如何在WebView中设置编辑框的值,以及在使用Javascript的PC上的浏览器中设置值.
它基本上首先找出编辑框的ID(文本),然后使用以下方法设置值:在PC上:
document.getElementById('xxxxxxxx').value = 'test'
Run Code Online (Sandbox Code Playgroud)
在Android中:
mWebView.loadUrl("javascript: document.getElementById('xxxxxxxx').value = 'test'");
Run Code Online (Sandbox Code Playgroud)
这个脚本在PC上运行,但是当我在WebView.loadUrl中调用脚本时,它只是覆盖我的整个页面以"测试".
这对我来说很奇怪,因为下面的android代码可以在单选按钮上运行,但是当它出现在编辑框中时,它就会失败.
mWebView.loadUrl("javascript: document.getElementById('xxxxxxxx').checked = true");
Run Code Online (Sandbox Code Playgroud)
你能帮我分析一下可能的原因吗?非常感谢.
为了说清楚,我在WebViewClient.onPageFinished(WebView视图,String url)中运行javascript代码.因此WebView应该完全加载.这也很有意义,因为我可以检查单选按钮.
我已经将图像文件读入ByteArray,但我怎么能把它写回来.我的意思是将ByteArray保存到文件系统中的映像文件中.PNG格式首选.
我从PNG文件到ByteArray的代码:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), mUri);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
Run Code Online (Sandbox Code Playgroud)
我知道有一些类似的问题,但我找不到这个问题的确切解决方案.谢谢!!!