bri*_*ian 5 android webview android-tabhost progress-bar
在Android应用程序中,我使用TabView,其中一个选项卡显示WebView.但是在网页加载之前页面是空白的.如何在页面加载之前显示进度条?它不能在标题栏中,因为它被标签主机隐藏.
bee*_*tra 17
我为此使用了ProgressBar.使用这样的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout [...]>
<WebView
android:id="@+id/WebView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ProgressBar
android:id="@+id/ProgressBar"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleLarge"
android:visibility="gone"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我使用以下方法隐藏并显示进度指示器:
WebView webView = (WebView) findViewById(R.id.WebView);
final ProgressBar progess = (ProgressBar) findViewById(R.id.ProgressBar);
webView.setWebViewClient(new WebViewClient() {
public void onPageStarted(WebView view, String url, Bitmap favicon) {
progess.setVisibility(View.VISIBLE);
}
public void onPageFinished(WebView view, String url) {
progess.setVisibility(View.GONE);
}
}
Run Code Online (Sandbox Code Playgroud)
Android 开发者网站上有一个非常好的教程。它展示了如何创建在整个 Android 程序中使用的“旋转轮”进度对话框,甚至还介绍了如何在单独的线程中处理加载以防止应用程序在加载时冻结的一些基础知识。
| 归档时间: |
|
| 查看次数: |
12823 次 |
| 最近记录: |