我试图用新的Splashscreens API替换我的Android应用程序中基于活动的启动画面
所以我创建了一个我的应用徽标的svg,创建主题,并在我的MainActivity中设置installSplashScreen
,但当应用启动时,Splashscreen中的徽标看起来像这样:
我该如何解决这个问题?
下面是我对style.xml所做的:
<style name="Theme.App.Starting" parent="Theme.SplashScreen">
<item name="windowSplashScreenBackground">@color/colorAccent</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_visual_vector</item>
<item name="postSplashScreenTheme">@style/AppTheme</item>
</style>
清单:
<activity
android:name=".MainActivity"
android:theme="@style/Theme.App.Starting"
android:screenOrientation="portrait"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
主要活动:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SplashScreen.installSplashScreen(this);
setContentView(R.layout.activity_main);
...
5条答案
按热度按时间kiz8lqtg1#
你可以做的是把你的图标包在一个嵌入的可绘制对象中,这样它就被绘制在圆的内部。
例如,创建一个
drawable/splash_inset.xml
资源:实际的插入值取决于您的图像及其纵横比,这里使用所有边缘上的
72dp
作为示例。然后将这个drawable应用为您的
windowSplashScreenAnimatedIcon
。wmtdaxz32#
在Android 12中,如果您的图标大于所需的大小,它将被切断。
没有图标背景的应用程序图标:这应该是288×288 dp,并且适合直径为192 dp的圆。
例如,如果图像的全尺寸为300×300 dp,则图标需要适合直径为200 dp的圆。圆外的所有内容都将不可见(屏蔽)。
更多信息:https://developer.android.com/guide/topics/ui/splash-screen#elements
lfapxunr3#
我发现最可靠的方法是使用Asset Studio来创建一个Adaptive Icon,它涵盖了DPI的所有场景。insets方法将引导您为不同的DPIMap不同的insets,此工具为您完成所有这些工作,并向您显示可以裁剪图像的位置。
然后将闪屏图标指向您生成的MIPMap
<item name="windowSplashScreenAnimatedIcon">@mipmap/ic_splash_screen</item>
使用调整大小滑块!
deikduxw4#
我的答案可能会晚,但我有同样的问题。我只添加了android:gravity=“center”到我的drawable/splash_logo.xml文件,并使用styles.xml文件中的splash_logo.xml。
8ulbf1ek5#
当我在模拟器30 s上运行我的应用程序时会发生这种情况,但是当我在物理设备上运行它时,它显示得很好。看看你上面的代码和评论,你真的需要从样式/Res实现图像吗?...我建议你在splash_screen. xml中创建imageView