Ionic splash screen and spinner

别来无恙 提交于 2019-12-30 10:44:11

问题


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 screen.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/37202147/ionic-splash-screen-and-spinner

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!