Android 12首次安装应用时Splash Screen图标不显示问题求助
Android 12 Splash API 首次启动图标缺失问题
在Android 12设备上首次安装应用后,启动时Splash Screen仅显示背景色,图标不出现;关闭应用再次启动,图标则正常显示。已按照官方文档完成所有Splash Screen实现步骤。
Manifest 配置
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.Android12Migrations"> <activity android:name=".views.MainActivity" android:exported="true" android:screenOrientation="portrait" android:theme="@style/SplashScreenTheme">
style.xml
<style name="SplashScreenTheme" parent="Theme.SplashScreen"> <item name="windowSplashScreenBackground">@color/teal_200</item> <item name="windowSplashScreenAnimatedIcon">@drawable/ic_app_logo</item> <item name="postSplashScreenTheme">@style/AppTheme</item> </style>
v31/style.xml
<style name="SplashScreenTheme" parent="Theme.SplashScreen"> <item name="windowSplashScreenBackground">@color/green</item> <item name="windowSplashScreenAnimatedIcon">@drawable/ic_app_logo</item> <item name="postSplashScreenTheme">@style/AppTheme</item> </style>
MainActivity 代码
class MainActivity : AppCompatActivity() { private val alarmManager by lazy { getSystemService(Context.ALARM_SERVICE) as AlarmManager } private val splashViewModel : SplashViewModel by viewModels() override fun onCreate(savedInstanceState: Bundle?) { installSplashScreen() super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val mainView = findViewById<View>(android.R.id.content) mainView.viewTreeObserver.addOnPreDrawListener( object : ViewTreeObserver.OnPreDrawListener{ override fun onPreDraw(): Boolean { //maybe checking locale or making some api to fetch some details if(splashViewModel.isDataLoaded.value == true){ mainView.viewTreeObserver.removeOnPreDrawListener(this) } return false } } ) }
SplashViewModel 代码
class SplashViewModel : ViewModel() { private val _isDataLoaded = MutableLiveData(false) val isDataLoaded: LiveData = _isDataLoaded init { viewModelScope.launch { delay(5000) _isDataLoaded.value = true } } }
问题演示视频
视频链接:https://drive.google.com/file/d/1LO_LCnnkQZdJ7DX_DYnHbGRfw_OrGZyc/view?usp=sharing
内容的提问来源于stack exchange,提问作者Amrit Chaturvedi
相关产品推荐
相关产品推荐

