How Android dynamically changes app desktop icons

From time to time, we will find that some common applications, such as a treasure and a East, will change the application icon on the desktop on some special days, such as double 11 and new year's day, in order to cater to the atmosphere of such a day. In fact, for such a desktop icon, Android provides us with the implementation of < activity alias > tag in androidmanifest.xml (for more articles, please pay attention to my wechat public account, QR code on the left).

We know that every time we write an activity, we need to configure it in androidmanifest before we can start it normally. In addition, we can also set an alias for it, that is, use the < activity alias > tag. The properties of this tag are consistent with the properties of < activity >, so we can make a simple analysis:

The above two properties are used to set icons and labels.

Although the alias name can be written arbitrarily, what I want to say is to set it as an activity as much as possible and keep it consistent with the name of < activity >. If it is not set as an activity name, I find that some mobile phones will have problems, which is better than the test machine I have now.

Whether this is a display alias. The default is true.

This is more important. The activity started by the specified alias must be consistent with the name of the original starting entry activity, and must be under the < activity > label.

The specific implementation is as follows:

The above is the default icon and the default activity entry.

The above is the specific startup method after adding the < activity alias > tag. We can control it by setting a switch on the server side. When the desktop icon is requested to be changed, we can close the current component component through the setcomponentenabledsetting() method provided by the packagemanager object and start the component component component corresponding to the alias, In order to change the icon quickly, we can restart the launcher application code. Name is a class name defined by ourselves. Remember to pass it to the full path, such as:

< activity alias > we can define multiple icons. We can dynamically change different icons at different times.

Remember to add permissions:

The above is Xiaobian's introduction to how Android dynamically changes the app desktop icon. I hope it will help you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>