Android学习笔记----Android简单有效的闪屏制作

本文介绍了如何在Android应用中实现启动画面(Splash Screen),通过使用Handler的postDelayed方法来延迟启动主活动,并提供了具体的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        new Handler().postDelayed(new Runnable(){
			public void run() {
                Intent mainIntent = new Intent(SplashActivity.this,MainActivity.class); 
                SplashActivity.this.startActivity(mainIntent); 
                SplashActivity.this.finish(); 
			}}, 10000);
    }

 

在API中对于Handler的postDelayed方法描述如下:

Android API 写道
final boolean postDelayed(Runnable r, long delayMillis) Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses.

 

将Runnable对象r在经过deleyMillis的时间后加入到消息队列,也就是讲过多久以后做什么事情就可以了。看起来很简单,有点类似于HTML里面的setTimeout和setInternal方法,使用也非常简单。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值