在WebView中显示ProgressDialog

时间:2017-12-19 21:03:19

标签: android webview

我已经搜索但我找不到实施我的webview的案例,我的webview dosnt打开一个网页,它只是加载我拥有的html,所以我需要一个进度条才能显示数据,我已经在我的内部声明了一个progressBar布局,这是我必须在webview中显示html的代码

mProgressBar = (ProgressBar) findViewById(R.id.pBar);

        mWebView = (WebView) findViewById(R.id.webview);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.loadDataWithBaseURL("", indicadores.toString(), "text/html", "UTF-8", "");

XML

<WebView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/webview"/>
            <ProgressBar
                android:layout_width="300dp"
                android:layout_height="300dp"
                android:id="@+id/pBar"
                android:layout_gravity="center"/>

在显示结果之前显示progressBar的最佳方法是什么。

由于

2 个答案:

答案 0 :(得分:0)

在具有进度条的浏览器中,当组件通过网络加载时,进度会递增。

如果您在本地拥有所有webview数据,则无法报告进度。没有任何地方可以增加进度。您需要webview能够报告它的渲染进度,而这不存在。

答案 1 :(得分:0)

您拥有自己的html文件,需要仅使用网络视图显示,此页面无需花费太多时间进行渲染。所以,如果你想使用进度条效果,你可以使用runnable。

<Window x:Class="ControlsOverlapWpf.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:ControlsOverlapWpf"
        mc:Ignorable="d"
        Title="MyProgram" d:DesignHeight="500" d:DesignWidth="500" ResizeMode="NoResize" WindowState="Normal" WindowStyle="None">
    <Canvas  Background="Pink">
        <Button Canvas.Top=" 200" Canvas.Left="200" Height="150" Width="150" Background="Aqua" HorizontalAlignment="Left" VerticalAlignment="Top" PreviewMouseLeftButtonDown="Control_MouseLeftButtonDown"  PreviewMouseLeftButtonUp="Control_MouseLeftButtonUp" PreviewMouseMove="Control_MouseMove" />
        <Button Canvas.Top=" 200" Canvas.Left="200" Height="150" Width="150" Background="Aqua" HorizontalAlignment="Left" VerticalAlignment="Top" PreviewMouseLeftButtonDown="Control_MouseLeftButtonDown"  PreviewMouseLeftButtonUp="Control_MouseLeftButtonUp" PreviewMouseMove="Control_MouseMove" />
        <Button Canvas.Top=" 200" Canvas.Left="200" Height="150" Width="150" Background="Aqua" HorizontalAlignment="Left" VerticalAlignment="Top" PreviewMouseLeftButtonDown="Control_MouseLeftButtonDown"  PreviewMouseLeftButtonUp="Control_MouseLeftButtonUp" PreviewMouseMove="Control_MouseMove" />
        <Button Canvas.Top=" 200" Canvas.Left="200" Height="150" Width="150" Background="Aqua" HorizontalAlignment="Left" VerticalAlignment="Top" PreviewMouseLeftButtonDown="Control_MouseLeftButtonDown"  PreviewMouseLeftButtonUp="Control_MouseLeftButtonUp" PreviewMouseMove="Control_MouseMove" />
        <Button Canvas.Top=" 200" Canvas.Left="200" Height="150" Width="150" Background="Aqua" HorizontalAlignment="Left" VerticalAlignment="Top" PreviewMouseLeftButtonDown="Control_MouseLeftButtonDown"  PreviewMouseLeftButtonUp="Control_MouseLeftButtonUp" PreviewMouseMove="Control_MouseMove" />
        <Button Canvas.Top=" 200" Canvas.Left="200" Height="150" Width="150" Background="Aqua" HorizontalAlignment="Left" VerticalAlignment="Top" PreviewMouseLeftButtonDown="Control_MouseLeftButtonDown"  PreviewMouseLeftButtonUp="Control_MouseLeftButtonUp" PreviewMouseMove="Control_MouseMove" />

    </Canvas>
</Window>

}

此处,等待时间 2秒您可以根据需要进行更改。