啟動頁加載的資源延伸至狀態(tài)欄展示钠署,如下圖:
我實(shí)現(xiàn)的方式是給activity設(shè)置主題和在activity中添加一句代碼:
主題:這個(gè)主題你要在Manifest.xml文件里邊配置到你的啟動頁activity
<style name="FullscreenTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!--這個(gè)是預(yù)先設(shè)置的背景圖片-->
<item name="android:windowBackground">@drawable/splash_bg</item>
<!--設(shè)置過渡效果喻圃,禁用窗口的預(yù)覽動畫-->
<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>
至此刊殉,你也可以實(shí)現(xiàn)啟動頁全屏的展示求晶,再也不用在啟動頁留一條狀態(tài)欄的黑邊了
順帶補(bǔ)充一點(diǎn):一般啟動頁都會加載圖片或者動態(tài)小視頻的廣告崖蜜,我的做法是用戶首次安裝應(yīng)用不顯示廣告只顯示默認(rèn)的啟動頁背景浊仆,首次啟動的同時(shí)將廣告資源存儲到本地,當(dāng)用戶下次打開app時(shí)開始展示廣告