本文介绍了Android的WebView中保留表单数据时改变方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何改变方向后保留在网页视图表单数据?
我已经使用的onSaveInstanceState(),我已经恢复使用previous状态 restoreState(savedInstanceState)。这成功地恢复了previous状态,方向的变化之前,但它并没有在网页视图窗体的文本框中恢复数据。

How to retain the form data in the webview after the change the orientation ?I have used onSaveInstanceState() and I have restored the previous state using restoreState(savedInstanceState). This successfully restores the previous state before the change in orientation but it does not restore the data in the text box of the form in the webview.

应该做哪些方位变化后,保留在网页视图形式的文本框中的数据?

What should be done to retain the data in the text box of the forms in webview after the change in orientation ?

注:我不会使用的android:configChanges =keyboardHidden |方向,因为我需要键盘输入的方向改变后,我的应用

Note: I would not be using android:configChanges="keyboardHidden|orientation" as I need keyboard input for my application after orientation changes.

先谢谢了。

推荐答案

随着web视图已被破坏并重新创建你将需要重新填充表单。您可以通过注入的JavaScript到Web视图做到这一点。

As the WebView has been destroyed and then recreated you will need to repopulate the form. You can do this by injecting javascript into the web view

例如以更新HTML元素的ID状态显示的文字

for example to update text displayed by HTML element id status

wevView.loadUrl(JavaScript的:document.querySelector('#地位)的innerHTML ='一些文本');

wevView.loadUrl("javascript:document.querySelector('#status').innerHTML = 'some text'");

这篇关于Android的WebView中保留表单数据时改变方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 08:25