Saturday, January 25, 2014

WebView first load will be black and white, seeking solutions


            
The code below, I am from MainActivity Click the button to jump into this page, the progress bar does not show up after the completion of the page, you must press the Return key again loaded to show up when you first load, So now do not know what the reason , seeking to help solve the Great God, ah, sick! !
 
public class AnnounceActivity extends BaseActivity {
private static final int PROGRESS_ID = 0;
private ProgressDialog progressBar = null;
private AlumniApp app;

private WebView webView = null;
Button aBackButton;

private static final String url = "http://m.alumni.ecnu.edu.cn/alumni/pages/indexs_noheader # notice";
@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);

app = (AlumniApp) getApplication ();
setContentView (R.layout.announce_layout);
aBackButton = (Button) this.findViewById (R.id.announce_back_btn);
Button freshButton = (Button) this.findViewById (R.id.announce_fresh_btn);
webView = (WebView) this.findViewById (R.id.webview);
freshButton.setOnClickListener (new View.OnClickListener () {
@ Override
public void onClick (View v) {
webView.goBack ();
}
});
aBackButton.setOnClickListener (new View.OnClickListener () {
@ Override
public void onClick (View v) {
Intent aIntent = new Intent (getApplicationContext (), MainActivity.class);
aIntent.setFlags (Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity (aIntent);
}

});

webView.getSettings () setJavaScriptEnabled (true);.
webView.getSettings () setBuiltInZoomControls (false);.
webView.getSettings () setPluginsEnabled (true);.
/ / / / WebView.getSettings () setPluginState (PluginState.ON);.
/ /
webView.getSettings () setUseWideViewPort (true);.
webView.getSettings () setLoadWithOverviewMode (true);.
/ / / / Solutions reported Cannot call method 'getItem' of null at XXXX / build.js: 6, etc. wrong question
webView.getSettings () setDomStorageEnabled (true);.
/ / WebView.getSettings () setLayoutAlgorithm (LayoutAlgorithm.SINGLE_COLUMN);.
progressBar = new ProgressDialog (this);
progressBar.setTitle ("Loading, please wait ...");
progressBar.setMessage ("Loading ...");
/ / ProgressBar = ProgressDialog.show (this, "Loading, please wait ...", "Loading ...");

webView.setWebViewClient (new WebViewClient () {
@ Override
public boolean shouldOverrideUrlLoading (WebView view, String url) {
view.loadUrl (url);
return true;
}
@ Override
public void onPageStarted (WebView view, String url, Bitmap favicon) {
progressBar.show ();
super.onPageStarted (view, url, favicon);
}
@ Override
public void onPageFinished (WebView view, String url) {
if (progressBar.isShowing ()) {
progressBar.dismiss ();
}

}
@ Override
public void onReceivedError (WebView view, int errorCode, String description, String failingUrl) {
/ / Error handling, pop-up dialog box displays
}
});

webView.setWebChromeClient (new WebChromeClient () {

@ Override
public void onProgressChanged (WebView view, int newProgress) {
progressBar.setProgress (newProgress);
progressBar.setMessage ("Loading ..." + newProgress + "%");

super.onProgressChanged (view, newProgress);
}
});

loadUrl (url);
}


public void loadUrl (String url)
{
if (webView! = null)
{
webView.loadUrl (url);
/ / ProgressBar = ProgressDialog.show (this, "Loading, please wait ...", "Loading ...");

}
}


@ Override
protected Dialog onCreateDialog (int id) {
if (id == PROGRESS_ID) {
return ProgressDialog.show (this, null, "Loading, please wait ......");
}
return super.onCreateDialog (id);
}
@ Override
protected void onResume () {
app.isStartSensor ();
super.onResume ();
}
@ Override
protected void onPause () {
app.isStopSensor ();
super.onPause ();
}
}


Reply:
Their first top one!
Reply:
Nobody view it, hurry!
Reply:
new one handle, direct callbacks after the end of the progress bar will be displayed content
Reply:
I just started to learn android, I ask how callbacks can specific? Thanks! Also for the first time does not show what causes it
Reply:
reference to the third floor kangming07 reply:
new one handle, callback directly after the end of the progress bar, the content is displayed

Help ah! ~ ~
Reply:
references, 4th Floor zzxwy2009 reply:
I just started learning android, I ask how callbacks can be more specific? Thanks! Also for the first time does not show what causes it
you put the entire code stickers, and have time to help you tune
Reply:
reference to the 6th floor kangming07 reply:
references, 4th Floor zzxwy2009 reply: I just started to learn android, I ask how callbacks can be more specific? Thanks! Also for the first time does not show is why you put the entire code stickers, and have time to help you tune



I found the problem, it may be that I have reason # URL link, I tried other pages are OK, that's not with # Finally, I thought of a way to make the page first loads, when loaded twice, be solve the problem surfaces, huh, or thank you anyway.
This is the code I modified later, you can also try
 
package ecnu.edu.cn.malumni;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;

public class AnnounceActivity extends BaseActivity {
private static final int PROGRESS_ID = 0;
private ProgressDialog progressBar;
private AlumniApp app;
private static int flag = 1;
private WebView webView;
Button aBackButton;
private static final String url = "http://m.alumni.ecnu.edu.cn/alumni/pages/indexs_noheader # notice";
@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);

app = (AlumniApp) getApplication ();
setContentView (R.layout.announce_layout);
aBackButton = (Button) this.findViewById (R.id.announce_back_btn);
Button freshButton = (Button) this.findViewById (R.id.announce_fresh_btn);
freshButton.setOnClickListener (new View.OnClickListener () {
@ Override
public void onClick (View v) {
webView.loadUrl (url);
}
});
aBackButton.setOnClickListener (new View.OnClickListener () {
@ Override
public void onClick (View v) {
Intent aIntent = new Intent (getApplicationContext (), MainActivity.class);
startActivity (aIntent);
}

});
webView = (WebView) this.findViewById (R.id.webview);
webView.getSettings () setJavaScriptEnabled (true);.
webView.getSettings () setBuiltInZoomControls (false);.
webView.getSettings () setPluginsEnabled (true);.
/ / WebView.getSettings () setPluginState (PluginState.ON);.

webView.getSettings () setUseWideViewPort (true);.
webView.getSettings () setLoadWithOverviewMode (true);.
/ / Solve the reported Cannot call method 'getItem' of null at XXXX / build.js: 6, etc. wrong question
webView.getSettings () setDomStorageEnabled (true);.
/ / WebView.getSettings () setLayoutAlgorithm (LayoutAlgorithm.SINGLE_COLUMN);.
progressBar = ProgressDialog.show (this, "Loading, please wait ...", "Loading ...");

webView.setWebViewClient (new WebViewClient () {
@ Override
public boolean shouldOverrideUrlLoading (WebView view, String url) {
view.loadUrl (url);
return true;
}
@ Override
public void onPageStarted (WebView view, String url, Bitmap favicon) {
}
@ Override
public void onPageFinished (WebView view, String url) {
if (flag == 1)
{
+ + Flag;
webView.reload ();
}
else {
progressBar.dismiss ();
}
}
@ Override
public void onReceivedError (WebView view, int errorCode, String description, String failingUrl) {
/ / Error handling, pop-up dialog box displays
}
});

webView.setWebChromeClient (new WebChromeClient () {

@ Override
public void onProgressChanged (WebView view, int newProgress) {
int totalpro = 50 * (flag-1) + newProgress / 2;
progressBar.setProgress (totalpro);
progressBar.setMessage ("Loading ......" + totalpro + "%");
super.onProgressChanged (view, totalpro);
}
});
webView.loadUrl (url);
}
@ Override
protected Dialog onCreateDialog (int id) {
if (id == PROGRESS_ID) {
return ProgressDialog.show (this, null, "Loading, please wait ......");
}
return super.onCreateDialog (id);
}
@ Override
protected void onResume () {
app.isStartSensor ();
super.onResume ();
}
@ Override
protected void onPause () {
app.isStopSensor ();
super.onPause ();
}
}


Reply:
You can turn off hardware acceleration

No comments:

Post a Comment