Dynamically change application icons Product: Can we dynamically change the App Icon in the Launcher? Development: No Product: Can we dynamically change the App Icon in the Launcher? Development: No Product: Can we dynamically change the App Icon in the Launcher? Development: No Product: Can we dynamically change the App Icon in the Launcher? Development: Let me think... Principle 1 — activity-alias In AndroidMainifest, there are two properties:
In addition, there is an activity-alias attribute, which can be used to create multiple different entrances. I believe that developers who have developed system settings and launchers should have seen a lot of them in the system source code. Principle 2——PM.setComponentEnabledSetting PackageManager is a general class that can manage all system components. Of course, if you root your device, you can also manage all components of other apps. Some system optimization tools disable some background services in this way. It is very easy to use:
According to the two flags PackageManager.COMPONENT_ENABLED_STATE_ENABLED and PackageManager.COMPONENT_ENABLED_STATE_DISABLED and the corresponding ComponentName, you can control whether a component is enabled. Dynamic Icon Change With the above two principles, the only thing left to achieve dynamic icon replacement is the idea. First, we create an Activity as the default entry with a default picture, then create an activity-alias for Double 11, pointing to the default Activity with a Double 11 picture, then create an activity-alias for Double 12, pointing to the default Activity with a Double 12 picture... and so on.
Wait, there is a problem with this, that is, this will display 3 entrances on the Launcher, so by default we will disable these activity-aliases first, and then enable them when they are needed. It takes a long time to train an army.
OK, after disabling the default Activity, enable the Double 11 activity-alias, the result remains unchanged and still points to the default Activity, but the icon has changed. Depending on the ROM, after disabling the component, you will wait for a while and the Launcher will automatically refresh the icon. See the picture below for the effect.
About the Columnist eclipse_xu: Senior Android development engineer; author of "Android Heroes", "Android Heroes: Magic Weapons", Android lecturer at MOOC; CSDN blog expert |
<<: Android Permission Management Principles (including 6.0)
>>: Experienced driver talks about racing technology: Android 7.0 adaptation experience
"Hotspot Review | Major Technology Events of...
Have you ever thought about how a 10-second video...
On the evening of September 24, 2021, Pan Dongshe...
Through this article, you will have a very system...
London in the late 19th century was a place full ...
When it comes to sightseeing in Chengdu, Longquan...
Due to conflicts of interest, I cannot name some ...
Speaking of voting activities , it is not new at ...
After we have mined and collected keywords, we fo...
If you are a web surfing enthusiast, you must hav...
Wildfires cannot be extinguished, and spring bree...
One minute with the doctor, the postures are cons...
In the social media industry, “speed is everythin...
Leviathan: This woman has been watched by countle...
Since the launch of the Cocos Game Development Co...