简体   繁体   English

根据 android:icon 动态更改应用程序主题

[英]Dynamically change application theme depending on android:icon

I have integrated splash screen into my app from android manifest I gave it a newly made SplashTheme and whenever the onActivityCreated called I change it to the one that is needed.我已将启动画面从 android manifest 集成到我的应用程序中,我给了它一个新制作的SplashTheme ,每当onActivityCreated调用时,我将其更改为需要的那个。 Now , in splash.xml file which you can see below:现在,在splash.xml文件中,您可以在下面看到:

<item>
    <color android:color="@color/colorPrimary" />
</item>

<item>
    <bitmap
        android:gravity="center"
        android:src="@mipmap/ic_launcher" />
</item>

I put my launcher ic_launcher in the center but when the device in which the app is installed uses round icons the splash screen still shows the "original" icon.我将启动器ic_launcher放在中心,但是当安装应用程序的设备使用圆形图标时,初始屏幕仍显示“原始”图标。 I know because I put here ic_launcher instead of ic_launcher_round but I would like to make this part dynamic, to recognize if the devices uses round icons put ic_launcher_round and the opposite.我知道是因为我放在这里ic_launcher而不是ic_launcher_round但我想让这部分动态,以识别设备是否使用圆形图标放置ic_launcher_round和相反。

Here is the part of my AndroidManifest.xml :这是我的AndroidManifest.xml的一部分:

Afaik, you cannot achieve the behavior you expect, simply because there does not exist an API, that would provide you whether current launcher uses round icon or a default icon. Afaik,您无法实现您期望的行为,仅仅是因为存在 API,可以为您提供当前启动器是使用圆形图标还是默认图标。

Instead, you should construct your splash screen in a way, that is not dependent on the default launcher implementation of the device.相反,您应该以一种不依赖于设备的默认启动器实现的方式构建启动画面。 Normally, you should have the same image regardless launcher uses round or normal icons.通常,无论启动器使用圆形图标还是普通图标,您都应该拥有相同的图像。

Leave launcher icons aside and create a resource specifically for splash screen.将启动器图标放在一边,并专门为启动画面创建一个资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM