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
For B-side products, holding events to acquire cu...
Foxconn's next investment location in mainlan...
Analysis of vocational skills training market Wit...
What does an operational plan that satisfies the ...
Pickled bamboo shoots with preserved vegetables, ...
I avoided the first day but couldn't avoid th...
Recently, a traffic accident occurred at the 1847...
In the Internet environment, it is said that traf...
As the world's third largest construction mac...
When we see someone with abundant body hair, we t...
Spring is here, and it's the perfect time to ...
Nowadays, there are more and more companies that ...
Produced by: Science Popularization China Author:...
In the ever-changing market, how should APP compl...
Douyin has no one to broadcast live, and the newl...