In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the "Android how to achieve custom progress bar WebView imitation Wechat loading" related knowledge, in the actual case of the operation process, many people will encounter such a dilemma, then let the editor lead you to learn how to deal with these situations! I hope you can read it carefully and be able to achieve something!
1. Custom webView
1. First define a class, inherit the webView, and first construct the method
Public class ProgressBarWebView extends WebView {}
Custom controls, first implement the construction method
The first is the internal instantiation of the program, which is passed into context.
Public ProgressBarWebView (Context context) {super (context);}
The second is used for layout instantiation, which brings the parameters of xml into the View through AttributeSet.
Public ProgressBarWebView (Context context, AttributeSet attrs) {super (context, attrs);}
The style information for the third topic is also brought in from XML
Public ProgressBarWebView (Context context, AttributeSet attrs, int defStyleAttr) {super (context, attrs, defStyleAttr);}
We need to load the progress bar layout, so we need to do it in the second constructor, as follows:
/ / first create a progress bar. What we create here is a horizontal progress bar progressBar = new ProgressBar (context, null, android.R.attr.progressBarStyleHorizontal); / / set the position parameter progressBar.setLayoutParams (new LayoutParams (LayoutParams.FILL_PARENT, 10,0,0)) of the progress bar; / / We want to set the background style of the progress bar Drawable drawable = context.getResources () .getDrawable (R.drawable.progress_bar_states) / / set the background style progressBar.setProgressDrawable (drawable); / / call its own addView (actually call the method in ViewManager to see the source code) method to add the progress bar to the current layout view addView (progressBar); / / normally want to get or interact with each other by implementing the following two methods: Myweblient () can restrict browsers that do not use the phone itself, MyChromeClient () can get the progress of web page loading, title and other setWebViewClient (new Myweblient ()) SetWebChromeClient (new MyChromeClient ()); / / whether you can scale getSettings () .setSupportZoom (true); getSettings () .setBuiltInZoomControls (true)
2. Rewrite WebViewClient and set its own webview to open without calling the browser of the system:
/ / need to set whether or not to open the mobile browser private class Myweblient extends WebViewClient {@ Override public boolean shouldOverrideUrlLoading (WebView view, String url) {view.loadUrl (url); return true;}}
3. Rewrite WebChromeClient, get the corresponding progress information, and set the
Private class MyChromeClient extends WebChromeClient {@ Override public void onProgressChanged (WebView view, int newProgress) {if (newProgress = = 100) {/ / when all the pages are loaded, progressBar.setVisibility (GONE);} else {if (progressBar.getVisibility () = = GONE) progressBar.setVisibility (VISIBLE); progressBar.setProgress (newProgress);} super.onProgressChanged (view, newProgress);}}
4. Constructor the progress bar background R.drawable.progress_bar_states we mentioned above needs to be defined in xml
Second, the use in the page
/ / in layout
Used in Activity
ProgressBarWebView webView= (ProgressBarWebView) findViewById (R.id.ss); webView.loadUrl ("http://www.baidu.com/");"
Third, the final effect
This is the end of the content of "how to achieve custom progress bar WebView imitation Wechat loading by Android". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.