Android开发--简单实现Android应用的启动页

本文介绍了如何在Android应用中实现3秒的启动页效果,包括创建SplashActivity、自定义布局、隐藏状态栏和标题栏,以及在AndroidManifest.xml中配置。展示了从代码到实际效果的完整过程。

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

Android启动页效果展示

平时打开手机的应用时,会跳出来3秒钟的广告后,再进入应用。今天我们就来简单实现一下引导页的功能。

1、首先,新建一个activity页面,命名:SplashActivity

在 activity_splash.xml中添加启动页内容,我这里添加了一个图片(图片放在drawable文件下),代码如下:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/zhz"
    tools:context=".SplashActivity">
<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/zhz"></ImageView>
</androidx.constraintlayout.widget.ConstraintLayout>

在java文件中,将启动页状态栏和标题栏隐藏,并设置启动页显示时间为3秒。

SplashActivity.java代码如下:

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //隐藏状态栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        //隐藏标题栏
        getSupportActionBar().hide();
        setContentView(R.layout.activity_splash);
        //创建子线程
        Thread mThread=new Thread(){
            @Override
            public void run() {
                super.run();
                try {
                    sleep(3000);//使程序休眠3秒
                    Intent intent=new Intent(getApplicationContext(),MainActivity.class);
                    startActivity(intent);
                    finish();
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        };
        mThread.start();//启动线程
    }
}

2、在AndroidManifest.xml文件中,设置启动页为.SplashActivity,代码如下:

<activity android:name=".StartActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

3、我这里将应用图标改为自己的图片了,你们根据自己需要(不改也行的),代码如下:

 到这里,你就完成了所有步骤了,运行一下试试吧!

运行结果如下:

Android启动页效果展示

当然,你还可以根据自己的需要,为启动页多添加些样式,加油!

评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值