Android splash screen 启动画面 初级

  1. 新建Android XML file 的welcome布局文件 -----启动画面界面

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/welcome_pic" > 
</LinearLayout>

    在res中新建文件夹drawable----将welcome_pic放在文件夹中,就可以引用了 

   2.   新建启动画面的activity,运行完后跳转到主界面

    新建class,welcome----添加以下代码

public class welcome extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcome); 
        //通过时间控制函数Timer 跳转
        new Timer().schedule(new TimerTask(){
                        @Override
			public void run() {
				startActivity(new Intent(welcome.this,MainActivity.class));
				finish(); 
			} 
        }, 3000);//单位是毫秒
    }
}

    3.  AndroidManiFest.xml设置 让启动界面先运行

    启动时,先进去welcome的activity,

<activity 
            android:name="com.pearl.splash_screen.welcome"
            android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
            >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER"  />
            </intent-filter>
        </activity>

    再设置跳转后的主界面

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
        </activity>

It's done

github下载: https://github.com/pearl2015/UI.git   splash screen


你可能感兴趣的:(Android splash screen 启动画面 初级)