Android custom WebView with progress bar imitates wechat loading process

In normal development, our client needs to load the web page with WebView. When the network is slow or the server responds, the page is blank. Therefore, for a better user experience, we can provide a loading progress bar to prompt the user that it is loading.

Structure of this document:

1. Customize WebView 2. Use in application 3. Effect display

1、 Customize WebView

1. First, define a class, inherit WebView, and construct a method

To customize the control, first implement the construction method. The first step is to instantiate the control inside the program and pass in the context

The second is used for layout instantiation, which will bring XML parameters into the view through attributeset

The style information of the third topic is also brought in from XML

We need to load the progress bar layout, so we need to operate in the second construction method, as follows:

2. Rewrite webviewclient, set its own WebView and open it without calling the system browser:

3. Rewrite the webchromeclient, obtain the corresponding progress information, and set the

4. The constructor we mentioned earlier is the progress bar background r.drawable.progress_ bar_ States, which need to be defined in XML;

2、 Use in pages

Used in activity

3、 Final effect

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>