Android启动页实现

本文详细介绍如何在Android应用中优化启动页体验,包括添加启动页Theme,设置透明背景,使用layer-list防止图片拉伸,以及如何将这些应用到启动页Activity中。

一、添加启动页的 Theme

    <style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar" />

    <style name="AppTheme.Splash" parent="AppTheme.Base">
        <item name="android:windowTranslucentNavigation">true</item>
        <item name="android:windowTranslucentStatus">true</item>
        <item name="statusBarBackground">@color/transparent</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowBackground">@drawable/lay_splash</item>
    </style>

使用 layer-list 作为背景图,防止 StartingWindow 拉伸图片。

注意:这里的背景图片如果是全屏的,要根据尺寸放对文件夹,不然会出现图片过大,过小等问题

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/white" />
    <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/ic_launcher" />
    </item>
</layer-list>

应用到启动页

        <activity
            android:name=".SplashActivity"
            android:exported="true"
            android:theme="@style/AppTheme.Splash">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

二、将启动页的背景设置为透明

适用于不做UI变化,直接进入到主页面的APP,从 StartingWindow 到进入主页面这段时间有很好的过度。

    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/transparent">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="这是启动页"
            app:layout_constraintTop_toTopOf="parent" />

    </androidx.constraintlayout.widget.ConstraintLayout>

参考链接:
Android APP应用启动页白屏(StartingWindow)优化
Android 全屏与沉浸式

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值