參考資料:http://blog.csdn.net/zivensonice/article/details/51691136
參考資料:http://blog.csdn.net/yanzhenjie1003/article/details/52201896
去掉狀態(tài)欄的代碼:
getWindow.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
我們平時這樣寫
<activity
android:name=".SplashActivity"
android:screenOrientation="portrait"
android:theme="@style/ThemeSplash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<style name="ThemeSplash" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@android:color/white</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="windowActionBar">false</item>
//一定要浙芙,否則有狀態(tài)欄顯示崖堤,不能全屏
<item name="windowNoTitle">true</item>
</style>
然后是SplashAcitivity的布局文件强挫,用一張圖片作為背景
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/bg_splash"
tools:context="com.example.makeapp.SplashActivity">
</LinearLayout>
然后是SplashActivity的代碼敲街,延遲2秒跳轉(zhuǎn)到主頁面
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
//延遲2S跳轉(zhuǎn)
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
}, 2000);
}
}
但是此時你會發(fā)現(xiàn)一個問題,就是點擊進入app后厚柳,會先白屏或是黑屏后度硝,然后才會進入splash頁面实蔽。
正確的姿勢
我們只需要對style中的ThemeSplash進行改動,只是給windowbackground設(shè)置背景就ok:
<style name="ThemeSplash" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/你的splash圖片</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="windowActionBar">false</item>
//一定要荡澎,否則有狀態(tài)欄顯示均践,不能全屏
<item name="windowNoTitle">true</item>
</style>
或者也可以這樣:
<style name="LuncherTheme" parent="@android:style/Theme.NoTitleBar.Fullscreen">
<item name="android:windowBackground">@drawable/splash</item>
</style>
ok,這樣就會是app秒起摩幔,而不會閃屏了