The difference between WebView loading completion and display completion is that webview Loading

Source: Internet
Author: User

The difference between WebView loading completion and display completion is that webview Loading

Please add address reprint: http://blog.csdn.net/jing110fei/article/details/46649079

The reason is that the project encountered such a problem. There is a WebView in a layout, followed by a Button in webView. When you enter this page, because webView is not loaded, the button is displayed at the top of the page. After webView is loaded, the button is obviously moved.

To solve this problem, I first want to drop the Button GONE and then perform a listener. After webView is loaded, the Button is displayed,

Therefore

MWebView. setWebViewClient (new WebViewClient () {@ Override public void onPageFinished (WebView view, String url) {// end super. onPageFinished (view, url) ;}@ Override public void onPageStarted (WebView view, String url, Bitmap favicon) {// start super. onPageStarted (view, url, favicon );}});
There is no logic problem, but in terms of the actual effect, there is a phenomenon of failed working.

The reason why webView reads data from the cache leads to inaccurate loading of the listener,

I set it to prevent webView from being read from the cache and retrieve it from the network each time.

mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); 
But it is still useless. The final analysis here should refer to the loading of the web page through webView or after obtaining the data is successful,

What we want is to listen to webView to display the data we want, and then let the Button display it,

So I tried to customize WebView.

Public class MyWebView extends WebView {public interface PlayFinish {void After ();} PlayFinish df; public void setDf (PlayFinish playFinish) {this. df = playFinish;} public MyWebView (Context context, AttributeSet attrs) {super (context, attrs);} public MyWebView (Context context) {super (context );} // onDraw indicates that the display is complete @ Override protected void onDraw (Canvas canvas) {super. onDraw (canvas); df. after ();}}

private MyWebView myWebView;
myWebView.setDf(new PlayFinish() {      @Override      public void After() {  btn_submit.setVisibility(View.VISIBLE);    }  });  

Then, the test was completed, and the onDraw () was rewritten. When the content in the webView in the application starts to be drawn, the button was displayed, which solved the problem.

Welcome to the discussion.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.