How add an Application Pre-loader/Startup screen/Splash Screen to My PhoneGap Android App

后端 未结 3 629
鱼传尺愫
鱼传尺愫 2020-12-31 17:28

I have created a Android app using phone Gap.It works fine.How I add a pre-loader image to My App.Now it show a white page while loading the application.

Help is hig

相关标签:
3条回答
  • 2020-12-31 17:32

    If by preloader image you mean a low-resolution version of the big image, you can use a VewSwitcher with two ImageViews in it: one image view contains the preloader image, while the other contains the full image (while it's loaded). Initially, you make the preloaded image visible, but when the big Bitmap finishes loading you just use switcher.showNext() to show the full image.

    Some further reading about the ViewSwitcher (the example does something similar): here

    0 讨论(0)
  • 2020-12-31 17:38

    You could create an AsyncTask implementation for showing an image / progress indicator while your application's data is loading in the background thread.

    1. In the async task's onPreExecute method you show the chosen preloader (image / ProgressDialog / etc)
    2. in the doInBackground method you start loading the necessary data, and
    3. in the onPostExecute method you remove/hide your preloader, so the activity's desired layout will be shown.
    0 讨论(0)
  • 2020-12-31 17:45

    If you mean pre-loader image has Splash screen refer the following code;

    For PhoneGap :

    public class MyDefaultActivity extends Activity {
    
       public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            super.setIntegerProperty("splashscreen", R.drawable.splash); // Displays the splash screen for android
            super.loadUrl("file:///android_asset/www/index.html",3000); // Second parameter is duration for delay of splash screen
        }
    }
    

    For Android Native app :

    public class MySplashScreen extends Activity {
        private CountDownTimer lTimer;
    
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.splashscreen); // Contains only an LinearLayout with backround as image drawable
    
            lTimer = new CountDownTimer(5000, 1000) {
                public void onFinish() {
                    closeScreen();
                }
                @Override
                public void onTick(long millisUntilFinished) {
                    // TODO Auto-generated method stub
                }
            }.start();
        }
    
        private void closeScreen() {
            Intent lIntent = new Intent();
            lIntent.setClass(this, MyLauncherActivity.class);
            startActivity(lIntent);
            finish();
        }
    }
    

    Make sure a file called splash.png is present as res/drawable-hdpi/splash.png (RGBA).

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