Android应用程序启动界面

最近在写安卓程序。许多优秀的APP启动界面都十分好看。启动之后出现一个Splash启动界面。

今天学到了一个方法。

使用两个Activity,利用线程造成一定的延时来执行Activity的跳转。所以添加一个SplashScreen,用来做为启动画面。另外一个就是我们自己真正的Activity。


下面是SplashSreen.java代码。

package cn.csu.demo;

import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;

public class SplashScreen extends ActionBarActivity {


	private final int SPLASH_DISPLAY_LENGHT = 1000; // 延迟1秒  
	  
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_splash_screen);  
  
        new Handler().postDelayed(new Runnable() {  
            public void run() {  
                Intent mainIntent = new Intent(SplashScreen.this,  
                        MainActivity.class);  
                SplashScreen.this.startActivity(mainIntent);  
                SplashScreen.this.finish();  
            }  
  
        }, SPLASH_DISPLAY_LENGHT);  
  
    }  

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.splash_screen, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}


下面两行代码启动一个新的Activity,同时关闭当前Activity。

   SplashScreen.this.startActivity(mainIntent);  
                SplashScreen.this.finish();  

但是由于我们程序之前AndroidManifest里面默认程序一开始启动的是MainActivity。我们需要对 AndroidManifest.xml文件进行更改。

        <activity
            android:name=".SplashScreen"
            android:label="@string/title_activity_splash_screen" >
            
             <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            
        </activity>

这样就可以完成自定义的启动界面了。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值