Displaying logo for few seconds at application start

后端 未结 7 1268
粉色の甜心
粉色の甜心 2021-02-08 07:13

I want to display a logo for few seconds before application starts and menu is visible. I want also to use some when it disappears. Should I create a new activity? Can I set it

相关标签:
7条回答
  • 2021-02-08 07:33

    You can use splash logo at startup using styles-only method. Unfortunately it works only starting form API 23. But you don't need manage splash Activity.

        <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
            ...
            <item name="android:windowBackground">@drawable/logo_startup</item>
            <item name="android:windowNoTitle">true</item>
        </style>
    

    res/drawable-v23/logo_startup.xml:

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item android:drawable="@color/PageBackground"/>
    
        <item android:width="@dimen/logo_startup" android:height="@dimen/logo_startup" android:gravity="center">
            <bitmap android:src="@drawable/logo"/> //use PNG file here, not vector
        </item>
    
    </layer-list>
    

    res/drawable/logo_startup.xml:

    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item android:drawable="@color/PageBackground"/>
    
    </layer-list>
    
    0 讨论(0)
  • 2021-02-08 07:34

    Here are a few intros to making a splash-page:

    http://www.barebonescoder.com/2010/04/a-simple-android-splash-screen/

    http://blogingtutorials.blogspot.com/2010/11/splash-graphics-activity-in-android.html

    Android SplashScreen

    0 讨论(0)
  • 2021-02-08 07:39

    You can use an image view that gets setVisibility(Visibility.GONE); or something to that extent, or you can write an activity that just pops up and drops out after a time ends. That is your personal preference...

    0 讨论(0)
  • 2021-02-08 07:41
    package com.karan.android.video;
    
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    
    public class splash extends Activity 
    {
    
       @Override
       public void onCreate(Bundle savedInstanceState) 
       {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.splash);
          Thread splashThread = new Thread() 
          {
             @Override
             public void run() 
             {
                try {
                   int waited = 0;
                   while (waited < 3000)
                   {
                      sleep(100);
                      waited += 100;
                   }
                } catch (InterruptedException e)
                {
                   // do nothing
                } finally 
                {
                   finish();
                   Intent i = new Intent(splash.this,video.class);
                   startActivity(i);
                }
             }
          };
          splashThread.start();
       }
    }
    
    Xml file:
    
    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout
       xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content">
    
         <ImageView           
             android:src="@drawable/buff"       
             android:id="@+id/ImageView01"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content">
          </ImageView>
    
        <TextView 
        android:textSize="40dp"
        android:textColor="#CCFF00"    
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"  
        android:text="Buffering..."
        /> 
    
    
    </FrameLayout>
    
    0 讨论(0)
  • 2021-02-08 07:42

    define a layout for the splash screen which will contain your logo , and then , add this code to your activity :

    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        //display the logo during 5 seconds,
        new CountDownTimer(5000,1000){
            @Override
            public void onTick(long millisUntilFinished){} 
    
            @Override
            public void onFinish(){
                   //set the new Content of your activity
                   YourActivity.this.setContentView(R.layout.main);
            }
       }.start();
    }
    
    0 讨论(0)
  • 2021-02-08 07:46

    Delayed execution can be implemented in simplier way:

    new Handler().postDelayed(new Runnable() {
      // ... Hide splash image and show the real UI
    }, 3000)
    

    Also the android standard android.widget.ViewSwitcher class is very usable for this kind of things.

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