Android 歡迎頁快速啟動
大家應該都知道,在默認情況下,Android App在點擊App logo到App完全啟動這之間會有一段時間空白期。那么如何做到在用戶點擊logo圖標之后立即打開App的界面而不是一段白屏或黑屏呢?
設置xml
在drawable下建立welcome.xml
<?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/welcome_page"/> </item></layer-list>
設置style
<!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> </style> <style name="WelcomeThem" parent="AppTheme"> <item name="android:windowBackground">@drawable/welcome</item> </style>
清單文件中配置style
<!-- 歡迎頁 --> <activity android:name=".ui.WelcomeActivity" android:windowSoftInputMode="adjustNothing" android:theme="@style/WelcomeThem"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity>
Activity中不需要設置setContentView()
public class WelcomeActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent intent = new Intent(this, MainActivity.class); startActivity(intent); finish(); }}不需要為你的SplashActivity設置一個視圖,這個視圖來自于主題,在主題中為你的SplashActivity設置UI就足夠了。
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對武林網的支持。
新聞熱點
疑難解答