Poi*_*ess 10 android splash-screen android-12 android-api-31
我正在使用Android 12 启动屏幕 API,虽然从启动器打开应用程序时启动屏幕图标显示没有问题,但从通知打开应用程序仅显示启动屏幕背景,没有图标或动画图标。
v31/styles.xml这是我的活动使用的主题AndroidManifest.xml:
<style name="MainActivityTheme" parent="AppTheme">
<item name="android:windowSplashScreenBackground">@color/splash_screen_background</item>
<item name="android:windowSplashScreenAnimatedIcon">@drawable/splash_screen_icon</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用其他主题,但无济于事:
<style name="SplashScreenTheme" parent="Theme.SplashScreen">
<item name="android:windowSplashScreenBackground">@color/splash_screen_background</item>
<item name="android:windowSplashScreenAnimatedIcon">@drawable/splash_screen_icon</item>
<item name="postSplashScreenTheme">@style/MainActivityTheme</item>
</style>
Run Code Online (Sandbox Code Playgroud)
欢迎任何使图标在通知中可见的想法。提前致谢!
经过一段时间的挣扎后,我发现这是Android 团队的预期行为,尽管尚不清楚确切原因,并且人们一直在抱怨它。因此,我开始研究新splashScreenStyle选项以解决该限制。
基本上,我只是创建一个新活动,将待处理的意图从通知转发到最初预期的活动,同时请求显示启动屏幕图标。
NotificationLaunchActivity以主题创作@style/Theme.AppCompat.Translucent
在onCreate()本次活动中:
Intent intent = new Intent(this, MainActivity.class);
intent.putExtras(getIntent());
Bundle options = new Bundle();
options.putInt("android.activity.splashScreenStyle", 1);
finish(); // Must finish the activity before
startActivity(intent, options);
Run Code Online (Sandbox Code Playgroud)
替换MainActivity.class为NotificationLaunchActivity.class现有通知构建器的 PendingIntent。
瞧,就这么简单。在少数 Android 12 设备上进行了测试,并按预期工作。
注意:据我所知,从深层链接、系统意图以及直接共享目标打开应用程序时,同样可以应用于显示启动屏幕图标。
| 归档时间: |
|
| 查看次数: |
3076 次 |
| 最近记录: |