启动页加载的资源延伸至状态栏展示,如下图:
我实现的方式是给activity设置主题和在activity中添加一句代码:
主题:这个主题你要在Manifest.xml文件里边配置到你的启动页activity
<style name="FullscreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!--这个是预先设置的背景图片-->
<item name="android:windowBackground">@drawable/splash_bg</item>
<!--设置过渡效果,禁用窗口的预览动画-->
<item name="android:windowDisablePreview">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:fullBackupOnly">true</item>
<item name="android:screenOrientation">portrait</item>
<item name="android:windowSoftInputMode">stateHidden</item>
<item name="android:configChanges">orientation|keyboardHidden|screenSize</item>
</style>
我们往往会在背景中加入自己的Logo,splash_bg.xml的代码:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<!--opacity="opaque" activity不透明的-->
<item android:drawable="@color/white" />
<item
android:gravity="bottom"
android:scaleType="center">
<!--tilMode属性用于定义背景的显示模式-->
<shape android:shape="rectangle">
<solid android:color="@color/white" />
</shape>
</item>
<!-- android:drawable="@drawable/logo" 你的logo-->
<item
android:width="155dp"
android:height="58dp"
android:drawable="@drawable/logo"
android:gravity="bottom|center_horizontal"
android:bottom="@dimen/dp_15"/>
</layer-list>
最后别忘了在你的activity中加如以下代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//是否全屏
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
以下顺便贴上启动页activity的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="newmatch.zbmf.com.testapplication.activitys.SplashActivity">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/screenIV"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/dp_88"
android:gravity="center"
android:keepScreenOn="true"
android:scaleType="centerCrop"
android:visibility="visible" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/skipAd"
android:layout_width="@dimen/dp_45"
android:layout_height="@dimen/dp_25"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="@dimen/dp_30"
android:layout_marginEnd="@dimen/dp_15"
android:background="@drawable/skip_ad_bg"
android:gravity="center"
android:padding="@dimen/dp_3"
android:text="@string/skip"
android:textColor="@color/white"
android:textSize="@dimen/sp_14" />
</RelativeLayout>
skip_ad_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/deepPurple_translate" />
<stroke
android:width="@dimen/dp_0_5"
android:color="@color/white" />
<corners android:radius="@dimen/dp_45" />
</shape>
至此,你也可以实现启动页全屏的展示,再也不用在启动页留一条状态栏的黑边了
顺带补充一点:一般启动页都会加载图片或者动态小视频的广告,我的做法是用户首次安装应用不显示广告只显示默认的启动页背景,首次启动的同时将广告资源存储到本地,当用户下次打开app时开始展示广告