Sunday, January 10, 2016

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 loading can be displayed when you first load, So now do not know what the reason , ask God to help solve the big ah, sick of it! !
 
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);.
// // Resolve newspaper Can not 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 look at it, hurry!
Reply:
a new handle, direct callback after the end of the progress bar, the content is displayed
Reply:
I just started learning android, ask how callbacks can be specific? thank! Also for the first time it does not show what causes it
Reply:
quote 3rd floor kangming07 reply:
new a handle, the progress bar directly after the end of the callback, the content is displayed

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



I found the problem, it may be that I have reason # URL links, I tried other pages are OK, with a # is not, finally, I thought of a way to make the page first loads, when loaded twice, be solve the problem of surface, Oh, thank you friends.
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);.
// Resolve newspaper Can not 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:
It can turn off hardware acceleration
Reply:
Enabling software acceleration join
inside the WebView Layoutandroid: layerType = "software"
Reply:
quote 9th floor chujingwei reply:
Enable software acceleration join
inside the WebView Layoutandroid: layerType = "software"


The Positive Solutions
Reply:
onresume () with onpuase () method which, app why there is wrong, said to be in transition

No comments:

Post a Comment