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
There is no doubt that Apple is the most profitab...
According to the WeChat official account of Yanhe...
Wang Xin Recently, researchers from the Universit...
Baidu bidding is a good thing. It can be said tha...
According to foreign media reports, mobile phone ...
"Ten years of exploring the secrets of peach...
General Bradley's 2021 Trading Strategy Lectur...
Many marketing and promotion personnel will use Q...
The Central Meteorological Observatory issued an ...
We may have never been so close to the future. Yo...
As the two giants in the mobile phone camp, Apple...
Recently, according to foreign media reports, the...
Building a healthy body, Liu Mengyi, three consec...
On August 31, 2022, the latest issue of "Chi...
In 1969, the first CCD image sensor was born in B...