机器人的WebView处理方向更改 [英] Android WebView handling orientation changes

查看:211
本文介绍了机器人的WebView处理方向更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚开始使用的WebView工作。问题是性能下旋转。 web视图已重新加载页面,它可以是一个有点乏味。

Just started working with the webview. The issue is performance following rotation. The WebView has to reload the page, which can be a bit tedious.

什么是最好的处理一个方向变化,而不从源头每次刷新页面?

What's the best of of handling an orientation change without reloading the page from source each time?

推荐答案

编辑:此方法不再起作用作为<一说href="http://developer.android.com/reference/android/webkit/WebView.html#saveState(android.os.Bundle)"相对=nofollow>文档

This method no longer works as stated in the docs

原来的答复:

这可以通过overrwriting处理的onSaveInstanceState(包outState)在你的活动,并呼吁 saveState和从web视图:

This can be handled by overrwriting onSaveInstanceState(Bundle outState) in your activity and calling saveState from the webview:

   protected void onSaveInstanceState(Bundle outState) {
      webView.saveState(outState);
   }

然后恢复这在你的onCreate后的WebView已经重新充气课程:

Then recover this in your onCreate after the webview has been re-inflated of course:

public void onCreate(final Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.blah);
   if (savedInstanceState != null)
      ((WebView)findViewById(R.id.webview)).restoreState(savedInstanceState);
}

这篇关于机器人的WebView处理方向更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆