Android webview retain form data when orientation changes

…衆ロ難τιáo~ 提交于 2019-12-10 09:36:10

问题


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 ?

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

Thanks in advance.


回答1:


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

for example to update text displayed by HTML element id status

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



来源:https://stackoverflow.com/questions/8725593/android-webview-retain-form-data-when-orientation-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!