[英]Splash-screen approach in single Activity app
我正在嘗試確定創建應用程序啟動屏幕的最佳方法,同時考慮到Google最新的建議,盡可能選擇單個活動應用程序。
看這里:
和這里:
“今天我們將導航組件作為構建您的應用內UI的框架,重點是將單活動應用程序作為首選架構。”
我找到的任何好的啟動畫面方法都有一個專門用於啟動畫面的活動:
有沒有其他人有過在單個Activity應用程序中創建啟動畫面的經驗? 單個活動建議是否包含啟動畫面,還是特殊情況? 有沒有人對此有任何好的例子或建議?
干杯,保羅。
我使用的方法如下:
首先為背景定義一個drawable:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/green"/>
<item>
<bitmap
android:gravity="center"
android:src="@mipmap/ic_launcher"/>
</item>
</layer-list>
2.定義要在splashScreen中使用的新樣式:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/background_splash</item>
</style>
3.使您的活動實現使用splash主題:
<activity
android:name=".MainActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
4.在創建時,在超級調用之前和設置內容視圖之前設置默認應用主題:
override fun onCreate(savedInstanceState: Bundle) {
setTheme(android.R.style.AppTheme)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main);
}
這種方法是我一直在使用的方法,即使是多項活動,因為它遵循谷歌制定的指導方針:它立刻引起轟動,並且不會停留超過需要的時間。
如果在布局中使用ConstraintLayout
,則可以使用Android的Group
類對多個視圖進行分組。 有關更多信息,請參閱以下鏈接。
https://developer.android.com/reference/android/support/constraint/Group
此類控制一組引用的窗口小部件的可見性。 通過添加到以逗號分隔的ID列表來引用窗口小部件,例如:
<android.support.constraint.Group
android:id="@+id/group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
app:constraint_referenced_ids="button4,button9" />
僅供參考 - 多個組可以引用相同的小部件 - 在這種情況下,XML聲明順序將定義最終的可見性狀態(最后聲明的組將具有最后一個單詞)。
希望這可以幫助您解決問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.