Android:首次从web显示空白屏幕在webview中加载URL
我试图在webview中加载多个URL,这些URL会在一段时间间隔后自动更改,除了每次第一次运行应用程序时,它会在前10秒(基本上是我设置的时间段)显示空白屏幕,然后加载第一个URL外,一切正常,我不知道为什么会这样 下面是我的代码Android:首次从web显示空白屏幕在webview中加载URL,android,timer,webview,Android,Timer,Webview,我试图在webview中加载多个URL,这些URL会在一段时间间隔后自动更改,除了每次第一次运行应用程序时,它会在前10秒(基本上是我设置的时间段)显示空白屏幕,然后加载第一个URL外,一切正常,我不知道为什么会这样 下面是我的代码 public class Gif_First extends Activity { WebView mWebView; CountDownTimer mTimer; @SuppressLint("SetJavaScriptEnabled") @Override
public class Gif_First extends Activity {
WebView mWebView;
CountDownTimer mTimer;
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.animation);
mTimer = new CountDownTimer(10000, 1000) {
private String[] myArray = {
"http://i.share.pho.to/efe195fd_o.gif",
"http://i.share.pho.to/cf478918_o.gif",
"http://i.share.pho.to/5ae5a0a9_o.gif",
"http://i.share.pho.to/17d0c96f_o.gif",
"http://i.share.pho.to/d2139e2d_o.gif" };
int currentIndex = 0;
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
if (currentIndex < myArray.length) {
mWebView.loadUrl(myArray[currentIndex]);
currentIndex++;
} else {
currentIndex = 0;
if (currentIndex < myArray.length)
mWebView.loadUrl(myArray[currentIndex]);
currentIndex++;
mTimer.start();
}
mTimer.start();
}
};
mTimer.start();
mWebView = (WebView) findViewById(R.id.webviewActionView);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebSliderWebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(mWebView, url);
//Toast.makeText(getApplicationContext(), "Done!",
// Toast.LENGTH_SHORT).show();
}
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
Toast.makeText(getApplicationContext(),
"Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
private class WebSliderWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
public void onPause() {
super.onPause();
mTimer.cancel();
}
}
public class Gif\u首先扩展活动{
网络视图;
倒数计时器;
@SuppressLint(“SetJavaScriptEnabled”)
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(窗口。功能\u无\u标题);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_全屏,
WindowManager.LayoutParams.FLAG(全屏);
setContentView(R.layout.animation);
mTimer=新的倒计时(10000,1000){
私有字符串[]myArray={
"http://i.share.pho.to/efe195fd_o.gif",
"http://i.share.pho.to/cf478918_o.gif",
"http://i.share.pho.to/5ae5a0a9_o.gif",
"http://i.share.pho.to/17d0c96f_o.gif",
"http://i.share.pho.to/d2139e2d_o.gif" };
int currentIndex=0;
公共void onTick(长毫秒未完成){
}
公共无效onFinish(){
if(currentIndex
提前谢谢。任何帮助都将不胜感激。语法“倒计时(开始时间、中间时间)
”。。更换代码mTimer=new CountDownTimer(10000,1000)
而不是mTimer=new CountDownTimer(0,1000)
希望它能工作。快乐编码…使用此自定义:
private class MyCountDown extends CountDownTimer
{
long duration, interval;
public MyCountDown(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
// TODO Auto-generated constructor stub
duration = millisInFuture;
interval = countDownInterval;
start();
}
@Override
public void onFinish() {
}
@Override
public void onTick(long duration) {
}
}
public class Gif\u首先扩展活动{
网络视图;
倒数计时器;
@SuppressLint(“SetJavaScriptEnabled”)
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(窗口。功能\u无\u标题);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_全屏,
WindowManager.LayoutParams.FLAG(全屏);
setContentView(R.layout.animation);
mTimer=新的MyCountDown(10000,1000);
mWebView=(WebView)findViewById(R.id.webviewActionView);
mWebView.getSettings().setJavaScriptEnabled(true);
setWebViewClient(新的WebLiderWebViewClient()){
@凌驾
公共void onPageFinished(WebView视图,字符串url){
super.onPageFinished(mWebView,url);
//Toast.makeText(getApplicationContext(),“完成!”,
//吐司。长度(短)。show();
}
@凌驾
接收错误时公共无效(WebView视图,int错误代码,
字符串说明,字符串失败(URL){
Toast.makeText(getApplicationContext(),
“哦,不!”+描述,吐司。长度(短)。显示();
}
});
}
@凌驾
公共布尔onKeyDown(int-keyCode,KeyEvent事件){
if((keyCode==KeyEvent.keyCode_BACK)&&mWebView.canGoBack()){
mWebView.goBack();
返回true;
}
返回super.onKeyDown(keyCode,event);
}
私有类WebSliderWebViewClient扩展WebViewClient{
@凌驾
公共布尔值shouldOverrideUrlLoading(WebView视图,字符串url){
view.loadUrl(url);
返回true;
}
}
公共无效暂停(){
super.onPause();
mTimer.cancel();
}
类MyCountDown扩展了倒计时
{
持续时间长,间隔时间长;
私有字符串[]myArray={
"http://i.share.pho.to/efe195fd_o.gif",
"http://i.share.pho.to/cf478918_o.gif",
"http://i.share.pho.to/5ae5a0a9_o.gif",
"http://i.share.pho.to/17d0c96f_o.gif",
"http://i.share.pho.to/d2139e2d_o.gif" };
int currentIndex=0;
公共MyCountDown(长百万未来,长倒计时间隔){
超级(毫秒未来,倒计时间隔);
//TODO自动生成的构造函数存根
持续时间=百万分之一秒;
间隔=倒计时间隔;
start();
}
@凌驾
公共无效onFinish(){
if(currentIndexpublic class Gif_First extends Activity {
WebView mWebView;
CountDownTimer mTimer;
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.animation);
mTimer = new MyCountDown(10000, 1000);
mWebView = (WebView) findViewById(R.id.webviewActionView);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebSliderWebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(mWebView, url);
//Toast.makeText(getApplicationContext(), "Done!",
// Toast.LENGTH_SHORT).show();
}
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
Toast.makeText(getApplicationContext(),
"Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
private class WebSliderWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
public void onPause() {
super.onPause();
mTimer.cancel();
}
class MyCountDown extends CountDownTimer
{
long duration, interval;
private String[] myArray = {
"http://i.share.pho.to/efe195fd_o.gif",
"http://i.share.pho.to/cf478918_o.gif",
"http://i.share.pho.to/5ae5a0a9_o.gif",
"http://i.share.pho.to/17d0c96f_o.gif",
"http://i.share.pho.to/d2139e2d_o.gif" };
int currentIndex = 0;
public MyCountDown(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
// TODO Auto-generated constructor stub
duration = millisInFuture;
interval = countDownInterval;
start();
}
@Override
public void onFinish() {
if (currentIndex < myArray.length) {
mWebView.loadUrl(myArray[currentIndex]);
currentIndex++;
} else {
currentIndex = 0;
if (currentIndex < myArray.length)
mWebView.loadUrl(myArray[currentIndex]);
currentIndex++;
}
}
@Override
public void onTick(long duration) {
}
}
}
mWebView.loadUrl("http://stackoverflow.com");
mTimer.start();
mWebView = (WebView) findViewById(R.id.webviewActionView);
mWebView.loadUrl("http://stackoverflow.com");
mWebView.getSettings().setJavaScriptEnabled(true);
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}