WebView加载页面Android [英] WebView loading page Android

查看:98
本文介绍了WebView加载页面Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序首先在onCreate上将网页作为WebView加载.我应该将其扩展到新线程中,因为它可能会挂起一会儿吗?或至少一种显示页面仍在加载的方式.偶尔会显示为白色几秒钟.

My app begins by loading a webpage as a WebView on onCreate. Should I extend this into a new thread since it may hang for a bit? Or at least a way to show that the page is still loading. It will display as white for a few seconds occasionally.

还有,有没有一种方法可以防止页面在方向改变时重新加载?

Also, is there a way to prevent the page from reloading on orientation change?

推荐答案

Web视图本身会处理线程,因此您不必担心.

the webview handles threading itself, so you don't need to worry about that.

您可以在页面开始和完成加载时注册回调.您可以设置进度条或任何您想要的东西.参见 WebChromeClient.onProgressChanged( )以获取详细信息.这是好的帖子,其中提供了一些详细信息.

you can register callbacks for when the page starts and finishes loading. it's up to you to put up a progress bar, or whatever you want. see WebChromeClient.onProgressChanged() for details. here's a good post that gives some details.

您可以在清单中添加一些内容,以告诉系统您不关心方向更改.将以下内容添加到您的活动定义中,

you can add something to your manifest to tell the system you don't care about orientation changes. add the following to your activity definition,

android:configChanges="orientation"

另一种选择是将您的应用锁定到一个方向或另一个方向,

the other option is to lock your app into one orientation or the other,

android:screenOrientation="portait"

这篇关于WebView加载页面Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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