由网友(Selfishness 私念)分享简介:我想添加进度条或加载栏我的应用程序,它使用的WebView。我要的应用程序设置来运行应用程序内的所有链接,但我很困惑于如何实现,只要点击一个链接上的进度条I am trying to add a progress bar or loading bar to my application which uses webv...
我想添加进度条或加载栏我的应用程序,它使用的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("https://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="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView xmlns:android="http://schemas.android.com/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("http://www.google.com");
相关推荐
最新文章