如何添加进度条在web视图

编程入门 行业动态 更新时间:2024-10-08 18:40:23
本文介绍了如何添加进度条在web视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想添加进度条或加载栏我的应用程序,它使用的WebView。我要的应用程序设置来运行应用程序内的所有链接,但我很困惑于如何实现,只要点击一个链接上的进度条

I am trying to add a progress bar or loading bar to my application which uses webview. I have to application set up to run all the links within the app but i am confused on how to implement a progress bar for whenever a link is clicked on

下面是我用我的code

here is my code that i am using

public class CULearnBrowser extends Activity { WebView webview; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); webview = (WebView) findViewById(R.id.webview); webview.setWebViewClient(new HelloWebViewClient()); webview.getSettings().setJavaScriptEnabled(true); webview.loadUrl("culearn.colorado.edu/webct/entryPageIns.dowebct"); } private class HelloWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } } public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) { webview.goBack(); return true; } return super.onKeyDown(keyCode, event); } }

下面是XML

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="schemas.android/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <WebView xmlns:android="schemas.android/apk/res/android" android:id="@+id/webview" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout>

任何帮助将大大AP preciated。我知道这不应该是很难,但我不能弄明白

any help would be greatly appreciated. I know it shouldnt be hard but i cant figure it out

推荐答案

这link可以帮助你。

我已经在你的code添加几行代码,现在它工作的罚款与进度条。

I have added few lines in your code and now its working fine with progress bar.

getWindow().requestFeature(Window.FEATURE_PROGRESS); setContentView(R.layout.main ); // Makes Progress bar Visible getWindow().setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON); webview = (WebView) findViewById(R.id.webview); webview.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { //Make the bar disappear after URL is loaded, and changes string to Loading... setTitle("Loading..."); setProgress(progress * 100); //Make the bar disappear after URL is loaded // Return the app name after finish loading if(progress == 100) setTitle(R.string.app_name); } }); webview.setWebViewClient(new HelloWebViewClient()); webview.getSettings().setJavaScriptEnabled(true); webview.loadUrl("www.google");

更多推荐

如何添加进度条在web视图

本文发布于:2023-11-26 09:28:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633561.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   进度条   web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!