我如何在Cordova应用程序中添加新的/更改旧的SplashScreen(离子4)

时间:2018-11-16 17:57:57

标签: android cordova ionic-framework ionic-native

首先,我对Java不好。

我有一个使用cordova插件的android应用程序。 我需要更改启动画面。正是我需要在启动屏幕上更改微调器。

这是负责此操作的Java代码的一部分。

private void spinnerStart() {
    cordova.getActivity().runOnUiThread(new Runnable() {
        public void run() {
            spinnerStop();

            spinnerDialog = new ProgressDialog(webView.getContext());
            spinnerDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    spinnerDialog = null;
                }
            });

            spinnerDialog.setCancelable(false);
            spinnerDialog.setIndeterminate(true);

            RelativeLayout centeredLayout = new RelativeLayout(cordova.getActivity());
            centeredLayout.setGravity(Gravity.CENTER);
            centeredLayout.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

            ProgressBar progressBar = new ProgressBar(webView.getContext());
            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
            progressBar.setLayoutParams(layoutParams);

            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
                String colorName = preferences.getString("SplashScreenSpinnerColor", null);
                if(colorName != null){
                    int[][] states = new int[][] {
                        new int[] { android.R.attr.state_enabled}, // enabled
                        new int[] {-android.R.attr.state_enabled}, // disabled
                        new int[] {-android.R.attr.state_checked}, // unchecked
                        new int[] { android.R.attr.state_pressed}  // pressed
                    };
                    int progressBarColor = Color.parseColor(colorName);
                    int[] colors = new int[] {
                        progressBarColor,
                        progressBarColor,
                        progressBarColor,
                        progressBarColor
                    };
                    ColorStateList colorStateList = new ColorStateList(states, colors);
                    progressBar.setIndeterminateTintList(colorStateList);
                }
            }

            centeredLayout.addView(progressBar);

            spinnerDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
            spinnerDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

            spinnerDialog.show();
            spinnerDialog.setContentView(centeredLayout);
        }
    });
}

全班 https://github.com/apache/cordova-plugin-splashscreen/blob/master/src/android/SplashScreen.java

我认为必须像那个家伙说的那样做(我说的是正确答案) Android custom progress bar with .gif file

但是我不知道imageview应该在哪里(还有动画列表)

1 个答案:

答案 0 :(得分:0)

我做到了。我正在创建可绘制和mipmap资源

            AnimationDrawable animationDrawable;

            ImageView mProgressBar = new ImageView(webView.getContext());
            mProgressBar.setImageResource(R.id.myprogressbar);

            mProgressBar.setBackgroundResource(R.drawable.myprogressbar);
            animationDrawable = (AnimationDrawable)mProgressBar.getBackground();
            mProgressBar.setVisibility(View.VISIBLE);
            animationDrawable.start();
            // mProgressBar.setVisibility(View.GONE);
            // animationDrawable.stop();



            centeredLayout.addView(mProgressBar);
            // centeredLayout.addView(progressBar);

            spinnerDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
            spinnerDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));