Ionic splash screen and spinner

前端 未结 2 956
感动是毒
感动是毒 2021-01-14 14:44

Is there a way to customize spinner in splash screen? Currently I am using cordova splashscreen plugin and I want to change the color of spinner that appears on the splash s

相关标签:
2条回答
  • 2021-01-14 15:35

    well providing color to ion-spinner isn't difficult. You can do like this
    css

    .spinner svg {
      width: 28px;
      height: 28px;
      stroke: #444;
      fill: #444;
    }
    

    html

    <ion-spinner icon="circles "class="spinner-energized"></ion-spinner>
    

    as per Ionic Docs.

    0 讨论(0)
  • 2021-01-14 15:44

    In platforms/android/src/org/apache/cordova/splashscreen/SplashScreen.java, at the top:

    import android.graphics.drawable.Drawable;
    import android.content.res.Resources;
    

    And further down the bottom replace with this function:

     // Show only spinner in the center of the screen
    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);
    
    
                Resources activityRes = cordova.getActivity().getResources();
                int spinnerResId = activityRes.getIdentifier("customspinner", "drawable", cordova.getActivity().getPackageName());
                Drawable customSpinner = activityRes.getDrawable(spinnerResId);
    
                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());
                progressBar.setIndeterminateDrawable(customSpinner);
                RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
                progressBar.setLayoutParams(layoutParams);
    
                centeredLayout.addView(progressBar);
    
                spinnerDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
                spinnerDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    
                spinnerDialog.show();
                spinnerDialog.setContentView(centeredLayout);
            }
        });
    }
    

    In platforms/android/res/drawable - add the folder if it doesn't exists - add the file customspinner.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <rotate xmlns:android="http://schemas.android.com/apk/res/android"
        android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0"
        android:toDegrees="360">
        <shape android:shape="ring" android:innerRadiusRatio="3"
            android:thicknessRatio="8" android:useLevel="false">
            <size android:width="76dip" android:height="76dip" />
            <gradient android:type="sweep" android:useLevel="false"
                android:startColor="#FFFFFFFF" 
                android:endColor="#00FFFFFF"
                android:angle="0"
                 />
        </shape>
    </rotate> 
    

    Original answer here: Cordova splash screen change spinner color on android

    0 讨论(0)
提交回复
热议问题