将加载指示符/进度条添加到Phonegap Android启动画面

dar*_*ten 9 android splash-screen webview jquery-mobile cordova

我有一个PhoneGap 1.4.1/jQueryMobile 1.0.1/Android项目,它显示res/drawable/splash.png就好了,一旦加载了WebView,启动画面就会消失.

我想在启动画面中添加某种进度指示器百分比文本,但到目前为止还没有成功.

我过去通过使用像这样的普通webview取得了成功:

myWebView.setWebViewClient(new WebViewClient() {
    @Override
    public void onPageFinished(WebView view, String url) {
        myLoadingView.setVisibility(View.GONE);
        myWebView.setVisibility(View.VISIBLE);
    }
});
myWebView.loadUrl(...);
Run Code Online (Sandbox Code Playgroud)

但所有这只是一个带有进度指示器文本和背景图像的布局,可以通过以下方式更新:

myWebView.setWebChromeClient(new WebChromeClient() {
    public void onProgressChanged(WebView view, int progress) {
        myLoadingView.setText(progress+"%");
    }
});
Run Code Online (Sandbox Code Playgroud)

有谁知道如何将这个功能添加到现有的PhoneGap实现中,或者知道我如何用自己的实现替换PhoneGap?

Wil*_*iew 5

我想我找到了一个解决方案(不是一个完整的解决方案,而是一个微调解决方案).在DroidGap子类中,您应该添加以下行:

super.setStringProperty("loadingDialog", "Wait, Loading...");
Run Code Online (Sandbox Code Playgroud)

这是我的完整例子

public class MainActivity extends DroidGap {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        super.setIntegerProperty("splashscreen", R.drawable.splash);
        // Display a native loading dialog.  Format for value = "Title,Message".  
        // (String - default=null)
        super.setStringProperty("loadingDialog", "Wait,Loading Demo...");

       super.loadUrl("file:///android_asset/www/index.html");
      }
}
Run Code Online (Sandbox Code Playgroud)

您可以在本节中设置几个属性,请参阅以下代码:https://svn.apache.org/repos/asf/incubator/callback/phonegap-android/branches/WebSockets/framework/src/com/phonegap /DroidGap.java


jka*_*ini 5

我终于设法在PhoneGap webView中添加了一个进度条,它将显示页面加载的进度(百分比).希望这对你有所帮助

正如其他答案所解释的那样,appView位于一个内部LinearLayout.受保护(因此继承)的变量根引用它LinearLayout.您可以View将此(无论)本机s添加到此变量中.

我是这样做的:

  1. 在res/layouts /中创建布局

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <ProgressBar
            android:id="@+id/progressBar1"
            style="@android:style/Widget.ProgressBar.Horizontal"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:maxHeight="10dip"
            android:minHeight="10dip" />
    
    </LinearLayout>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 按照添加WebView进度条通常会遵循的所有步骤操作:

    final Activity activity = this;
    private ProgressBar progessBar1;
    
    Run Code Online (Sandbox Code Playgroud)
  3. 添加您创建的布局:

    View footer = View.inflate(getContext(), R.layout.mainshop, null);
    root.addView(footer);
    
    Run Code Online (Sandbox Code Playgroud)

    If you add it after calling super.loadURL(...); it will be displayed at the bottom. If you add it before, the layout will be displayed before the appView.

  4. 之后你只需添加:

    progessBar1 = (ProgressBar) findViewById(R.id.progressBar1);
    
    this.appView.setWebChromeClient(new WebChromeClient() {
    
            public void onProgressChanged(WebView view, int progress) { 
                activity.setProgress(progress * 1000);
                if(progress < 100 && progessBar1.getVisibility() == ProgressBar.GONE) {
                    progessBar1.setVisibility(ProgressBar.VISIBLE);
                }
                progessBar1.setProgress(progress);
                if(progress == 100) {
                    progessBar1.setVisibility(ProgressBar.GONE);
                }
    
                Log.d("Progress", progress+"");
    
             }
        });
    
    Run Code Online (Sandbox Code Playgroud)

干杯!